コード例 #1
0
def _execute(command):
    param = ["{\"serverId\":\"" + command["serverId"] + "\"}"]
    s1 = AosServerService.route_service("ThriftApiService", "getById", param)
    d1 = json.loads(s1)
    output = ""
    for k1 in d1:
        output = os.popen("su - " + k1["user"] + " -s /bin/bash " +
                          sys.path[0] + "/api/extend/1/deploy.sh " +
                          k1["baseDir"] + ' ' + k1["serverName"] + ' ' +
                          k1["serverId"] + ' ' + k1["warAdress"] + ' ' +
                          command["version"] + ' ' + k1["host"] + ' ' +
                          k1["userName"] + ' ' + k1["passWord"] + ' ' +
                          k1["port"]).read()
        state = '1'
        param = [
            "{\"id\":\"" + command["id"] + "\",\"state\":\"" + state +
            "\",\"mac\":\"" + MachineUtil.get_mac_address() + "\",\"msg\":\"" +
            output + "\",\"version\":\"" + command["version"] + "\"}"
        ]
        AosServerService.route_service("ThriftApiService", "editState", param)

        output2 = os.popen("su - " + k1["user"] + " -s /bin/bash " +
                           sys.path[0] + "/api/extend/1/deploy1.sh " +
                           k1["baseDir"] + ' ' + k1["serverName"] + ' ' +
                           k1["serverId"] + ' ' + k1["warAdress"] + ' ' +
                           command["version"] + ' ' + k1["host"] + ' ' +
                           k1["userName"] + ' ' + k1["passWord"] + ' ' +
                           k1["port"]).read()
        param = [
            "{\"id\":\"" + command["id"] + "\",\"state\":\"" + state +
            "\",\"mac\":\"" + MachineUtil.get_mac_address() + "\",\"msg\":\"" +
            output2 + "\",\"version\":\"" + command["version"] + "\"}"
        ]
        AosServerService.route_service("ThriftApiService", "editState", param)
コード例 #2
0
def _execute(command):
    try:
        config = FileUtils.get_instance('config.ini')
        containerId = command["serverId"]
        c = docker.Client(base_url='unix://var/run/docker.sock',
                          version=config.get_prop("docker-config", "api"),
                          timeout=10)
        c.remove_container(container=containerId)
        time.sleep(5)
        log = "true"
        output = base64.encodestring(log)
        state = '1'
        param = [
            "{\"id\":\"" + command["id"] + "\",\"state\":\"" + state +
            "\",\"mac\":\"" + MachineUtil.get_mac_address() + "\",\"msg\":\"" +
            output + "\",\"version\":\"" + command["version"] + "\"}"
        ]
        AosServerService.route_service("ThriftApiService", "editState", param)
    except Exception, ex:
        LogUtil.error(ex)
        log = ("Error {0}".format(str(ex)))
        output = base64.encodestring(log)
        state = '1'
        param = [
            "{\"id\":\"" + command["id"] + "\",\"state\":\"" + state +
            "\",\"mac\":\"" + MachineUtil.get_mac_address() + "\",\"msg\":\"" +
            output + "\",\"version\":\"" + command["version"] + "\"}"
        ]
        AosServerService.route_service("ThriftApiService", "editState", param)
コード例 #3
0
def _execute(command):
    try:
        commandInfo = command["commandInfo"]
        line = commands.getstatusoutput(commandInfo)
        log = json.dumps(line[1])
        output = base64.encodestring(log)
        state = '1'
        param = [
            "{\"id\":\"" + command["id"] + "\",\"state\":\"" + state +
            "\",\"mac\":\"" + MachineUtil.get_mac_address() + "\",\"msg\":\"" +
            output + "\",\"version\":\"" + command["version"] + "\"}"
        ]
        AosServerService.route_service("ThriftApiService", "editState", param)
    except Exception, ex:
        LogUtil.error(ex)
        log = ("Error {0}".format(str(ex)))
        output = base64.encodestring(log)
        state = '1'
        param = [
            "{\"id\":\"" + command["id"] + "\",\"state\":\"" + state +
            "\",\"mac\":\"" + MachineUtil.get_mac_address() + "\",\"msg\":\"" +
            output + "\",\"version\":\"" + command["version"] + "\"}"
        ]
        AosServerService.route_service("ThriftApiService", "editState", param)
コード例 #4
0
def _execute(config):
    monitor_state = config['state']
    if int(monitor_state) == 1:
        monitor_info = config['commandInfo']
        monitor_infos = monitor_info.split('#LOGMONITOR#')
        if len(monitor_infos) < 2:
            return
        MonitorManager.start_instance(monitor_infos[0], monitor_infos[1])
    elif int(monitor_state) == -1:
        monitor_info = config['commandInfo']
        monitor_infos = monitor_info.split('#LOGMONITOR#')
        if len(monitor_infos) < 2:
            return
        MonitorManager.stop_instance(monitor_infos[0], monitor_infos[1])
        param = ["{\"mac\":\"" + MachineUtil.get_mac_address() + "\",\"configId\":\"" + config['id'] + "\"}"]
        AosServerService.route_service("ThriftApiService", "removeStartupConfig", param)
コード例 #5
0
def _execute(command):
    LogUtil.info("程序检测中")
    mac = MachineUtil.get_mac_address()
    param = ["{\"mac\":\"" + mac + "\"}"]
    s1 = AosServerService.route_service("ThriftApiService",
                                        "getMonitoringData", param)
    d1 = json.loads(s1)
    for k1 in d1:
        if k1["serverType"] == "5001":
            os.popen("sh " + sys.path[0] + "/api/extend/6000/mysql.sh " +
                     k1["serverUserName"] + ' ' + k1["serverPassword"] + ' ' +
                     k1["projectDir"] + ' ' + k1["projectPort"]).read()
        if k1["serverType"] == "5002":
            os.popen("su - " + k1["user"] + " -s /bin/bash " + sys.path[0] +
                     "/api/extend/6000/redis.sh " + k1["serverUserName"] +
                     ' ' + k1["serverPassword"] + ' ' + k1["projectDir"] +
                     ' ' + k1["projectPort"]).read()
        if k1["serverType"] == "5003":
            os.popen("su - " + k1["user"] + " -s /bin/bash " + sys.path[0] +
                     "/api/extend/6000/mongodb.sh " + k1["serverUserName"] +
                     ' ' + k1["serverPassword"] + ' ' + k1["projectDir"] +
                     ' ' + k1["projectPort"]).read()
        if k1["serverType"] == "5004":
            os.popen("su - " + k1["user"] + " -s /bin/bash " + sys.path[0] +
                     "/api/extend/6000/flume.sh " + k1["serverUserName"] +
                     ' ' + k1["serverPassword"] + ' ' + k1["projectDir"] +
                     ' ' + k1["projectPort"]).read()
        if k1["serverType"] == "5005":
            LogUtil.info("检测rabbitMQ")
            os.popen("sh " + sys.path[0] + "/api/extend/6000/rabbitmq.sh " +
                     k1["serverUserName"] + ' ' + k1["serverPassword"] + ' ' +
                     k1["projectDir"] + ' ' + k1["projectPort"]).read()
        if k1["serverType"] == "5006":
            os.popen("su - " + k1["user"] + " -s /bin/bash " + sys.path[0] +
                     "/api/extend/6000/zookeeper.sh " + k1["serverUserName"] +
                     ' ' + k1["serverPassword"] + ' ' + k1["projectDir"] +
                     ' ' + k1["projectPort"]).read()
        if k1["serverType"] == "5007":
            os.popen("su - " + k1["user"] + " -s /bin/bash " + sys.path[0] +
                     "/api/extend/6000/jstorm.sh " + k1["serverUserName"] +
                     ' ' + k1["serverPassword"] + ' ' + k1["projectDir"] +
                     ' ' + k1["projectPort"]).read()
コード例 #6
0
 def _regist_node(self):
     mac = MachineUtil.get_mac_address()
     ip = NodeLifeTime.config.get_prop("aos-config", "client_ip")
     docker = NodeLifeTime.config.get_prop("docker-config", "docker")
     docker_status = "0"
     docker_images = "[]"
     docker_containers = "[]"
     if docker == "1":
         docker_status = DockerUtil._docker_status(NodeLifeTime.api)
     if docker_status == "2":
         docker_status = DockerUtil._docker_restart(mac, NodeLifeTime.api)
     if docker_status == "1":
         docker_images = base64.encodestring(
             DockerUtil._docker_images(NodeLifeTime.api))
         docker_containers = base64.encodestring(
             DockerUtil._docker_containers())
     param = [
         "{\"mac\":\"" + mac + "\",\"ip\":\"" + ip +
         "\",\"dockerStatus\":\"" + docker_status +
         "\",\"dockerImages\":\"" + docker_images + "\",\"containers\":\"" +
         docker_containers + "\"}"
     ]
     LogUtil.info("注册节点信息:%s" % (json.dumps(param)))
     return AosServerService.route_service("ThriftApiService", "add", param)
コード例 #7
0
def _execute(command):
    config = FileUtils.get_instance('config.ini')
    nginx_conf_dir = config.get_prop("nginx-config", "nginx_conf_dir")
    nginx_conf_dir_bak = config.get_prop("nginx-config", "nginx_conf_dir_bak")
    os.system('mkdir -p ' + nginx_conf_dir)
    os.system('cp -r ' + nginx_conf_dir + nginx_conf_dir_bak)
    os.system('rm -rf ' + nginx_conf_dir + '*')
    state = '0'
    try:
        for k1 in command:
            upstreamName = k1["upstreamName"]
            upstreamNode = json.loads(k1["upstreamNode"])
            fileName = nginx_conf_dir + upstreamName + '.conf'
            os.system('touch ' + fileName)
            c = nginx.Conf()
            LogUtil.info("Node信息:%s" % (upstreamNode))
            t = ''
            for k2 in range(len(upstreamNode)):
                if (k2 == 0):
                    t = 'server' + ' ' + upstreamNode[k2][
                        "ipAdress"] + ' ' + upstreamNode[k2]["strategy"] + ';\n'
                if (0 < k2 < len(upstreamNode) - 1):
                    t = t + '     ' + 'server' + ' ' + upstreamNode[k2][
                        "ipAdress"] + ' ' + upstreamNode[k2]["strategy"] + ';\n'
                if (k2 == len(upstreamNode) - 1):
                    t = t + '     ' + 'server' + ' ' + upstreamNode[k2][
                        "ipAdress"] + ' ' + upstreamNode[k2]["strategy"]
            ipHash = k1["ipHash"]
            if (ipHash == '1'):
                u = nginx.Upstream(upstreamName, nginx.Key('', t),
                                   nginx.Key('', 'ip_hash'))
                c.add(u)
            if (ipHash == '0'):
                u = nginx.Upstream(upstreamName, nginx.Key('', t))
                c.add(u)
            s = nginx.Server()
            s.add(
                nginx.Key('listen', k1["nginxListenPort"]),
                nginx.Key('server_name', k1["nginxServerName"]),
                nginx.Key('access_log', k1["accessLog"]),
                nginx.Location(
                    '= /',
                    nginx.Key('proxy_pass', 'http://' + k1["upstreamName"]),
                    nginx.Key('proxy_redirect', 'off'),
                    nginx.Key('proxy_set_header', 'Host    $host'),
                    nginx.Key('proxy_set_header', 'X-Real-IP  $remote_addr'),
                    nginx.Key('proxy_set_header',
                              'X-Forwarded-For   $proxy_add_x_forwarded_for')))
            c.add(s)
            nginx.dumpf(c, fileName)
        LogUtil.info("完成Nginx配置")
        output = os.popen('service nginx restart').read()
        state = '1'
        param = [
            "{\"mac\":\"" + MachineUtil.get_mac_address() + "\",\"state\":\"" +
            state + "\",\"msg\":\"" + output + "\"}"
        ]
        os.system('rm -rf ' + nginx_conf_dir_bak)
        AosServerService.route_service("ThriftApiService", "nginxLog", param)
    except Exception, ex:
        LogUtil.error(ex)
        os.system('rm -rf ' + nginx_conf_dir)
        os.system('mv ' + nginx_conf_dir_bak + nginx_conf_dir)
        os.system('service nginx restart')
        output = ex.message
        state = '2'
        param = [
            "{\"mac\":\"" + MachineUtil.get_mac_address() + "\",\"state\":\"" +
            state + "\",\"msg\":\"" + output + "\"}"
        ]
        AosServerService.route_service("ThriftApiService", "nginxLog", param)
コード例 #8
0
def _execute(command):
    param = ["{\"serverId\":\"" + command["serverId"] + "\"}"]
    s1 = AosServerService.route_service("ThriftApiService", "getMiddleServerById", param);
    d1 = json.loads(s1)
    output = ""
    for k1 in d1:
        output = output + os.popen("wget  -O command.sh " +  k1["installCommand"]).read();
        output = output + os.popen("su - " + k1["user"] + " -s /bin/bash " + sys.path[0] + "/../../../bin/command.sh " + k1["serverUserName"] + ' ' +k1["serverPassword"]+ ' ' +k1["projectDir"]+ ' ' +k1["projectPort"]+ ' ' +k1["flumeIp"]+ ' ' +k1["flumeRabbitMqIp"]+ ' ' +k1["flumeRabbitMqQueueName"]+ ' ' +k1["flumeRabbitMqUserName"]+ ' ' +k1["flumeRabbitMqPassword"]+ ' ' +k1["flumeRabbitMqPort"]+ ' ' +k1["flumeRabbitMqExchange"]).read();
        output = output + os.popen("rm -rf command.sh").read();
	output =base64.encodestring(output)
        state = '1'
        param = ["{\"id\":\"" + command["id"] + "\",\"state\":\"" + state + "\",\"mac\":\"" + MachineUtil.get_mac_address() + "\",\"msg\":\"" + output +
                       "\",\"version\":\"" + "" + "\"}"]
        AosServerService.route_service("ThriftApiService", "editState", param)
コード例 #9
0
 def _nginx_conf(self):
     mac = MachineUtil.get_mac_address()
     param = ["{\"mac\":\"" + mac + "\"}"]
     LogUtil.info("拉取Nginx配置信息:%s" % (json.dumps(param)))
     return AosServerService.route_service("ThriftApiService",
                                           "getNginxConf", param)