#!/usr/bin/env python
# -----------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
# -----------------------------------------------------------------------


import os
import sys

from ducc_util  import DuccUtil

class DuccVaryOff(DuccUtil):

    
    def usage(self, msg):
        if ( msg != None ):
            print msg

        print 'vary_off list-of-nodes'
        print '    This marks the nodes named in the list offline for scheduling purposes.'
        print '    All jobs, services, and managed reservations are canceled on the nodes.'
        print ''
        print 'Example:'
        print '   vary_off node1 node2 node3'

        sys.exit(1)
    
    def main(self, nodes):

        if ( len(nodes) == 0 ):
            self.usage(None)

        print 'Varying off', nodes
        DUCC_JVM_OPTS = ' -Dducc.deploy.configuration=' + self.DUCC_HOME + "/resources/ducc.properties "
        DUCC_JVM_OPTS = DUCC_JVM_OPTS + ' -DDUCC_HOME=' + self.DUCC_HOME
        DUCC_JVM_OPTS = DUCC_JVM_OPTS + ' -Dducc.head=' + self.ducc_properties.get('ducc.head')
        self.spawn(self.java(), DUCC_JVM_OPTS, 'org.apache.uima.ducc.common.main.DuccRmAdmin', '--varyoff', ' '.join(nodes)) 
        
        return

if __name__ == "__main__":
    instance = DuccVaryOff()
    instance.main(sys.argv[1:])

    
