Beispiel #1
0
    def __init__(self, environment, verbose=False,  **keyword_args):
        self.verbose = verbose
        self.env = environment
        has_errors = False

        if self.env.conn_info["token"] is None:
            print("Token is required!")
            has_errors = True

        #Accesing with JUDOOR or COLLAB token have have different parameters in the PyUnicore.Transport
        # oidc=False doesnt work with collab token
        self.transport = None
        if Utils.ACCESS_JUDOOR == self.env.conn_info["methodToAccess"]:
            self.transport = unicore_client.Transport(self.env.conn_info["token"], oidc=False)
        elif Utils.ACCESS_COLLAB == self.env.conn_info["methodToAccess"]:
            self.transport = unicore_client.Transport(self.env.conn_info["token"])

        self.registry = unicore_client.Registry(self.transport, self.env.conn_info["serverToRegister"])
        self.site = self.registry.site(self.env.conn_info["serverToConnect"])
        self.client = unicore_client.Client(self.transport, self.site.site_url)
        self.storage= None


        # Get the object Storage
        # Endpoint of Storage is mapped from env variables of your account into the UNICORE
        if self.env.conn_info["serverProjectName"]:
            # we need to access to the right project folder into the HPC system
            # First, setting an environment variable by a job
            if verbose:
                print("Creating environment variables into UNICORE system")
                result = self.one_run(steps=["jutil env activate -p "+str(self.env.conn_info["serverProjectName"])+" \n",
                                             "echo $PROJECT"])

                if len(result["stderr"]) > 0:
                    print("Error", result["stderr"])
                    has_errors = True
                else:
                    print(" - Variable $PROJECT is now", result["stdout"])

                # Second, consume the Storage Endpoint generated by PyUnicore from the env var of previous step.
                for obj in self.site.get_storages():
                    if obj.storage_url.endswith(self.env.urls["destiny_server_endpoint"]):
                        self.storage = obj
                        break
                if not self.storage:
                    print("Source not available",self.env.urls["destiny_server_endpoint"])
                    has_errors = True

        else:
            print("Project name is required!")
            has_errors = True

        if has_errors:
            exit(1)
Beispiel #2
0
    def stop_operation(operation_id):
        # TODO: Review this implementation after DAINT maintenance
        operation = dao.get_operation_by_id(operation_id)
        if not operation or operation.has_finished:
            LOGGER.warning("Operation already stopped: %s" % operation_id)
            return True

        LOGGER.debug("Stopping HPC operation: %s" % str(operation_id))
        op_ident = OperationDAO().get_operation_process_for_operation(
            operation_id)
        if op_ident is not None:
            # TODO: Handle login
            transport = unicore_client.Transport(
                os.environ[HPCSchedulerClient.CSCS_LOGIN_TOKEN_ENV_KEY])
            # Abort HPC job
            job = Job(transport, op_ident.job_id)
            if job.is_running():
                job.abort()

        # Kill thread
        operation_thread = get_op_thread(operation_id)
        if operation_thread is None:
            LOGGER.warning("Thread for operation {} is not available".format(
                operation_id))
        else:
            operation_thread.stop()
            while not operation_thread.stopped():
                LOGGER.info(
                    "Thread for operation {} is stopping".format(operation_id))
        BurstService().persist_operation_state(operation, STATUS_CANCELED)
        return True
 def __init__(self, token):
     self.token = token
     self.tr = new_unicore_client.Transport(
         self.token.split('Bearer ')[1])
     self.daint_client = new_unicore_client.Client(
         self.tr, 'https://brissago.cscs.ch:8080/DAINT-CSCS/rest/core')
     self.daint_storage = self.daint_client.get_storages()
Beispiel #4
0
 def _get_site(self) -> unicore_client.Client:
     if self._site is None:
         tr = unicore_client.Transport(self.get_token())
         registry = unicore_client.Registry(
             tr, unicore_client._HBP_REGISTRY_URL)
         self._site = registry.site("DAINT-CSCS")
     return self._site
Beispiel #5
0
 def pyunicore_transport(self, access_token=None, set_preferences=False):
     if not access_token:
         access_token = self.auth_state.get("access_token")
     unicore_cert = os.environ.get("UNICORE_CERT", False)
     transport = unicore_client.Transport(access_token,
                                          oidc=True,
                                          verify=unicore_cert)
     if set_preferences:
         transport.preferences = "uid:{account},group:{project}".format(
             account=self.account, project=self.project)
     return transport
Beispiel #6
0
 def _build_unicore_client(auth_token, registry_url, supercomputer):
     # type: (str, str, str) -> Client
     transport = unicore_client.Transport(auth_token)
     registry = unicore_client.Registry(transport, registry_url)
     return registry.site(supercomputer)