Exemple #1
0
def cleanup_endpoints():
    try:
        data_handler = DataHandler()
        dead_endpoints = data_handler.GetDeadEndpoints()
        for endpoint_id, dead_endpoint in dead_endpoints.items():
            print("\n\n\n\n\n\n----------------Begin to cleanup endpoint %s" %
                  endpoint_id)
            endpoint_description_path = os.path.join(
                config["storage-mount-path"],
                dead_endpoint["endpointDescriptionPath"])
            still_running = get_k8s_endpoint(endpoint_description_path)
            # empty mean not existing
            if still_running == "":
                print("Endpoint already gone %s" % endpoint_id)
                status = "stopped"
            else:
                output = k8sUtils.kubectl_delete(endpoint_description_path)
                # 0 for success
                if output == 0:
                    status = "stopped"
                    print("Succeed cleanup endpoint %s" % endpoint_id)
                else:
                    print("Clean dead endpoint %s failed, endpoints: %s" %
                          (endpoint_id, dead_endpoint))

            dead_endpoint["status"] = status
            dead_endpoint["lastUpdated"] = datetime.datetime.now().isoformat()
            data_handler.UpdateEndpoint(dead_endpoint)
    except Exception as e:
        traceback.print_exc()
    finally:
        pass
def cleanup_endpoints():
    try:
        data_handler = DataHandler()
        try:
            dead_endpoints = data_handler.GetDeadEndpoints()
            for endpoint_id, dead_endpoint in dead_endpoints.items():
                try:
                    logger.info("Begin to cleanup endpoint %s", endpoint_id)
                    point = get_k8s_endpoint(dead_endpoint["id"])
                    if point is None:
                        logger.debug("Endpoint already gone %s", endpoint_id)
                        status = "stopped"
                    else:
                        delete_resp = delete_k8s_endpoint(point.metadata.name)
                        logger.info("delete_resp for endpoint is %s",
                                    delete_resp)
                        status = "stopped"
                    # we are not changing status from "pending", "pending" endpoints are planed to setup later
                    if dead_endpoint["status"] != "pending":
                        dead_endpoint["status"] = status
                    dead_endpoint["lastUpdated"] = datetime.datetime.now(
                    ).isoformat()
                    data_handler.UpdateEndpoint(dead_endpoint)
                except Exception as e:
                    logger.exception("clanup endpoint failed %s", dead_endpoint)
        except Exception as e:
            logger.exception("clean up endpoint failed")
        finally:
            data_handler.Close()
    except Exception as e:
        logger.exception("close data handler failed")
def cleanup_endpoints():
    try:
        data_handler = DataHandler()
        try:
            dead_endpoints = data_handler.GetDeadEndpoints()
            for endpoint_id, dead_endpoint in dead_endpoints.items():
                try:
                    logger.info(
                        "\n\n\n\n\n\n----------------Begin to cleanup endpoint %s",
                        endpoint_id)
                    endpoint_description_path = os.path.join(
                        config["storage-mount-path"],
                        dead_endpoint["endpointDescriptionPath"])
                    still_running = get_k8s_endpoint(endpoint_description_path)
                    # empty mean not existing
                    if still_running == "":
                        logger.info("Endpoint already gone %s", endpoint_id)
                        status = "stopped"
                    else:
                        output = k8sUtils.kubectl_delete(
                            endpoint_description_path)
                        # 0 for success
                        if output == 0:
                            status = "stopped"
                            logger.info("Succeed cleanup endpoint %s",
                                        endpoint_id)
                        else:
                            # TODO will need to clean it up eventually
                            status = "unknown"
                            logger.info(
                                "Clean dead endpoint %s failed, endpoints: %s",
                                endpoint_id, dead_endpoint)

                    # we are not changing status from "pending", "pending" endpoints are planed to setup later
                    if dead_endpoint["status"] != "pending":
                        dead_endpoint["status"] = status
                    dead_endpoint["lastUpdated"] = datetime.datetime.now(
                    ).isoformat()
                    data_handler.UpdateEndpoint(dead_endpoint)
                except Exception as e:
                    logger.warning(
                        "Clanup endpoint failed {}".format(dead_endpoint),
                        exc_info=True)
        except Exception as e:
            logger.exception("cleanup endpoint failed")
        finally:
            data_handler.Close()
    except Exception as e:
        logger.exception("close data handler failed")