예제 #1
0
def before_first_request():
    print("########### Init the inner db")
    try:
        db.create_all(bind="octopus_inner")
    except Exception as e:
        mainLogger.exception(str(e))
        raise Exception(e)
예제 #2
0
 def delete(self):
     output = {"retcode": 0, "stdout": "success"}
     try:
         db.drop_all(bind="octopus_inner")
     except Exception as e:
         mainLogger.exception(str(e))
         output = {"retcode": 1, "stdout": str(e.args)}
     return output
예제 #3
0
    def post(self):
        args = self.parser.parse_args()
        mainLogger.info("the Nodemeta_XML args is {0}".format(args))

        nodemeta_xml_file = args.get("Nodemeta_XML")

        output = {"retcode": 0, "stdout": "success"}
        try:
            load_metadata(nodemeta_xml_file=nodemeta_xml_file)
        except Exception as e:
            mainLogger.exception(str(e))
            messages = str(e.args)
            output = {"retcode": 1, "stdout": messages}
        return output
예제 #4
0
    def post(self):
        args = self.parser.parse_args()

        mainLogger.debug("the AddInfaEnvs args is {0}".format(args))
        mainLogger.debug("the AddInfaEnvs locals is {0}".format(locals()))
        infa_envs_args = args.get("Envs")  # type: str
        infa_envs_dict = dict()

        try:
            envs_list = infa_envs_args.split(",")
            for env in envs_list:
                env_list = env.split("=", maxsplit=1)
                if len(env_list) < 2:
                    raise WrongEnvrionmentFormatException(
                        "{0} is not right, the standard format is env_name=env_value"
                        .format(env))
                infa_envs_dict.setdefault(env_list[0], env_list[1])
            current_node = get_current_node()
            infa_env_inst = INFA_ENV()
            ## upsert
            for key, value in infa_envs_dict.items():
                env_dict = {key: value}
                try:
                    infa_env_inst.update_env(current_node.id, env_dict)
                except Exception as e:
                    mainLogger.exception(
                        "Updating {0} with error: {1}, and now try to insert it"
                        .format(env_dict, str(e)))
                    infa_env_inst.insert_env(current_node.id, env_dict)
            ret_message = {
                "retcode": 0,
                "stdout": infa_envs_dict,
                "stderr": None
            }
        except Exception as e:
            mainLogger.exception(str(e))

            ret_message = ({
                "retcode":
                1,
                "stdout":
                None,
                "stderr":
                "Error {0} when upserting {1} into inner database.".format(
                    str(e.args), infa_envs_dict)
            }, 404)
        return ret_message
예제 #5
0
    def delete(self, envs: str):
        mainLogger.debug(
            "InfaEnvs Delete method  parameters is {0}".format(envs))
        current_node = get_current_node()
        infa_env_inst = INFA_ENV()
        envs_list = envs.split(",")
        stdout = ""
        stderr = ""
        for env in envs_list:
            try:
                infa_env_inst.delele_env(current_node.id, env=env)
                stdout += "{0}, ".format(env)
            except Exception as e:
                mainLogger.exception(str(e))
                stderr += "Delete the {0} with error {1} or it's not exisitng. \t".format(
                    env, str(e.args))

        ret_message = {"retcode": 0, "stdout": stdout[:-2], "stderr": stderr}

        return ret_message
예제 #6
0
 def get_NodeConfig(self):
     """
     :return: GatewayNodeConfig | WorkerNodeConfig
     """
     # gateway nodes
     try:
         nodeConfig = self.get_gw_GatewayNodeConfig()
     except Exception as e:
         mainLogger.exception(
             "{0}, and Will try to use the worker node configuration".
             format(str(e)))
         # worker nodes
         try:
             nodeConfig = self.get_wk_WorkerNodeConfig()
         except Exception as e:
             mainLogger.exception(
                 "Will try to use the worker node configuration")
             raise NotFoundMetadataTypesException(
                 "Neither the Gateway nor Worker node existing")
     return nodeConfig
예제 #7
0
파일: isp.py 프로젝트: lianyouli/Octopus
def purgeLog(
    BeforeDate: str,
    DomainName: str = None,
    UserName: str = None,
    Password: str = None,
    SecurityDomain: str = "Native",
    Gateway: str = None,
    ResilienceTimeout: int = None,
) -> namedtuple("PurgeLogResult", ['retcode', 'stdout', 'stderr']):
    """
    purge log events for a domain or for application services, such as the PowerCenter Integration Service,
    the Data Integration Service, and the Web Services Hub.

    :param BeforeDate: (MM/dd/yyyy|yyyy-MM-dd)
    :param DomainName:
    :param UserName:
    :param Password:
    :param SecurityDomain:
    :param Gateway:
    :param ResilienceTimeout:
    :return: namedtuple("PurgeLogResult", ['retcode', 'stdout', 'stderr'])
    """
    subcmd = "PurgeLog"
    options = [
        "DomainName",
        "UserName",
        "Password",
        "SecurityDomain",
        "Gateway",
        "ResilienceTimeout",
        "BeforeDate",
    ]

    cmd = _checking_infacmd_env_and_ret_base_cmd(domainname=DomainName,
                                                 username=UserName,
                                                 password=Password,
                                                 cmd=base_cmd,
                                                 subcmd=subcmd)
    try:
        datetime.strptime(BeforeDate, "%Y-%m-%d")
    except Exception as e:
        mainLogger.exception(str(e))
        try:
            datetime.strptime(BeforeDate, "%m/%d/%Y")
        except Exception as e:
            mainLogger.exception(str(e))
            raise Exception(
                "The format of the BeforeDate is not right, should be yyyy/MM/dd or MM/dd/yyyy"
            )

    options_value_dict = locals()
    for option in options:
        cmd = _assemble_command_options(cmd, option,
                                        options_value_dict.get(option))

    mainLogger.debug(cmd)
    res = run_cmd(cmd, env=os.environ)
    mainLogger.info(res)
    stdout = res.stdout  # type: str
    stderr = res.stderr  # type: str
    if res.retcode == 0:
        pass
    else:
        stderr += stdout
    purgeLogResult = namedtuple("PurgeLogResult",
                                ['retcode', 'stdout', 'stderr'])
    return purgeLogResult(res.retcode, stdout, stderr)