Example #1
0
    def post(self):
        args = self.parser.parse_args()
        mainLogger.debug("## args =  {0}".format(args))
        if is_none(args.get("ServiceName")) or is_none(args.get("Application")) or is_none(args.get("Workflow")):
            raise MissingRequiredParametersException(" ServiceName and  Application and  Workflow  are/is requried")
        # return serilization type
        ret_type = args.get("RT")
        if ret_type is None:
            ret_type = "JSON"

        # current_node_envs = infa_env.get_envs(current_node.id)  # type: dict
        current_node_envs = get_current_node_infa_envs()
        os.environ.update(current_node_envs)
        mainLogger.debug("environment variables is {0}".format(current_node_envs))
        args.pop("RT")

        res = startWorkflow(**args)
        mainLogger.debug(res)
        stdout = str(res.stdout)
        if ret_type.upper() == "PROTOBUF":
            proto_resp = infaCliResponse_pb2.InfaCliResponse()
            proto_resp.retcode = res.retcode
            proto_resp.stdout = stdout
            res = proto_resp.SerializeToString()
            mainLogger.debug("protobuf: the result is {0}".format(res))
            content_type = Config.PREDEFINED_CONTENT_TYPES.get("PROTOBUF")
        else:
            output_dict = {"retcode": res.retcode,
                           "stdout": stdout
                           }
            res = json.dumps(output_dict)
            content_type = Config.PREDEFINED_CONTENT_TYPES.get("JSON")
        response = make_response(res)
        response.headers["Content-Type"] = content_type
        return response
Example #2
0
    def post(self):
        args = self.parser.parse_args()
        mainLogger.info("the pmpasswd args is {0}".format(args))
        encrypt_type = args.get("EncryptType")
        passwd = args.get("Passwd")
        if encrypt_type is None or encrypt_type not in (
                'CRYPT_DATA', 'CRYPT_SYSTEM') or passwd is None:
            abort(401)
        ret_type = args.get('RT')  # type: str

        if ret_type is None:
            ret_type = "JSON"

        # node = Node()
        # current_node = node.get_current_node()  # type: Node
        #
        # infa_env = INFA_ENV()
        #
        # set_task_envs = infa_env.get_envs(current_node.id)
        set_task_envs = get_current_node_infa_envs()
        print("############## os.environ is {0}".format(os.environ))
        os.environ.update(set_task_envs)

        commandResult = pmpasswd(
            passwd,
            encrypt_type=encrypt_type)  # type: namedtuple("pmpasswdResult",
        #  ['retcode', 'stdout'])
        content_type = None
        if ret_type.upper() == "PROTOBUF":
            pmpasswd_resp = infaCliResponse_pb2.InfaCliResponse()
            pmpasswd_resp.retcode = commandResult.retcode
            pmpasswd_resp.stdout = commandResult.stdout
            commandResult = pmpasswd_resp.SerializeToString()
            mainLogger.debug(
                "protobuf: the result is {0}".format(commandResult))
            content_type = Config.PREDEFINED_CONTENT_TYPES.get("PROTOBUF")
        else:
            commandResult = json.dumps(commandResult._asdict())
            content_type = Config.PREDEFINED_CONTENT_TYPES.get("JSON")
        response = make_response(commandResult)
        response.headers["Content-Type"] = content_type
        return response
Example #3
0
    def post(self):
        """
        提交backup domain命令
        :return:
        """
        args = self.parser.parse_args()
        mainLogger.info(args)
        backup_path = args.get('backup_path')

        # return serilization type
        ret_type = args.get('RT')  # type: str
        if ret_type is None:
            ret_type = "JSON"

        # domain = Domain()
        current_domain = g.domain  # type: agent.database.metadata.Domain

        # node = Node()
        # current_node = node.get_current_node()  # type: Node
        current_node = g.current_node # type: agent.database.metadata.Node


        if not current_node.is_gateway:
            raise UnsupportedOperationsException(
                "current node is worker node, it doesn't supported to backup domain operation")

        # infa_env = INFA_ENV()
        # current_node_envs = infa_env.get_envs(current_node.id)  # type: dict
        current_node_envs = g.infa_envs # type: dict
        os.environ.update(current_node_envs)
        mainLogger.debug("environment variables is {0}".format(current_node_envs))
        commandResult = backupDomain(domainname=current_domain.name,
                                     databasetype=current_domain.db_type,
                                     databaseaddress="{0}:{1}".format(current_domain.db_host.rstrip(),
                                                                       current_domain.db_port),
                                     databaseusername=current_domain.db_username,
                                     databaseservicename=current_domain.db_service_name,
                                     backupfile=backup_path,
                                     force=False,
                                     tablespace=current_domain.db_tablespace,
                                     schemaname=current_domain.db_schema,
                                     databasetlsenabled=current_domain.db_tls_enabled,
                                     databasetruststorepassword=current_domain.db_truststorepassword,
                                     trustedconnection=current_domain.db_trustedconnection,
                                     encryptionkeylocation=current_node.sc_secretkeysdirectory,
                                     databasetruststorelocation=current_domain.db_truststore_location
                                     )
        message = "backupfile: {0}".format(commandResult.backupfile)
        output_dict = {"retcode": commandResult.retcode,
                       "stdout": commandResult.stdout,
                       "messages": message}
        mainLogger.info(output_dict)

        if ret_type.upper() == "PROTOBUF":
            backdomain_resp = infaCliResponse_pb2.InfaCliResponse()
            backdomain_resp.retcode = commandResult.retcode
            backdomain_resp.stdout = commandResult.stdout
            backup_info = backdomain_resp.messages.add()
            backup_info.name = "backupfile"
            backup_info.value = commandResult.backupfile
            commandResult = backdomain_resp.SerializeToString()
            mainLogger.debug("protobuf: the result is {0}".format(commandResult))
            content_type = Config.PREDEFINED_CONTENT_TYPES.get("PROTOBUF")
        else:
            commandResult = json.dumps(output_dict)
            content_type = Config.PREDEFINED_CONTENT_TYPES.get("JSON")
        response = make_response(commandResult)
        response.headers["Content-Type"] = content_type
        return response