Пример #1
0
    def _undeploy(location: Path, inv: ExtendedInvocation):

        # get blueprint
        CSAR_db.get_revision(inv.blueprint_id, location, inv.version_id)
        # get session data (.opera)
        if not InvocationService.get_dot_opera_from_db(inv.deployment_id,
                                                       location):
            raise MissingDeploymentDataError(
                'Could not get .opera data from previous job, aborting...')

        with xopera_util.cwd(location):
            try:
                if inv.user_id and Settings.secure_workdir:
                    xopera_util.setup_user([location], inv.user_id,
                                           inv.access_token)
                opera_storage = Storage.create(".opera")
                if inv.inputs:
                    opera_storage.write_json(inv.inputs, "inputs")
                opera_undeploy(opera_storage,
                               verbose_mode=False,
                               num_workers=inv.workers)
                # Outputs in undeployment are not returned
                return None
            finally:
                if inv.user_id and Settings.secure_workdir:
                    xopera_util.cleanup_user()
Пример #2
0
    def prepare_two_workdirs(deployment_id: str,
                             blueprint_id: str,
                             version_id: str,
                             inputs: dict,
                             location: Path = None):
        location_old = InvocationService.deployment_location(
            str(uuid.uuid4()), str(uuid.uuid4()))
        location_new = location or InvocationService.deployment_location(
            str(uuid.uuid4()), str(uuid.uuid4()))

        # old Deployed instance
        # TODO Next line should use PostgreSQL.get_deployment_status(deployment_id), had to be changed since
        #  old blueprint_id is part of second to last invocation, last is already current
        inv_old = PostgreSQL.get_last_completed_invocation(deployment_id)
        CSAR_db.get_revision(inv_old.blueprint_id, location_old,
                             inv_old.version_id)
        InvocationService.get_dot_opera_from_db(deployment_id, location_old)
        storage_old = Storage.create(str(location_old / '.opera'))

        # new blueprint
        CSAR_db.get_revision(blueprint_id, location_new, version_id)
        storage_new = Storage.create(str(location_new / '.opera'))
        storage_new.write_json(inputs or {}, "inputs")
        storage_new.write(str(entry_definitions(location_new)), "root_file")

        return storage_old, location_old, storage_new, location_new
Пример #3
0
    def _deploy_continue(location: Path, inv: ExtendedInvocation):

        # get blueprint
        CSAR_db.get_revision(inv.blueprint_id, location, inv.version_id)
        # get session data (.opera)
        InvocationService.get_dot_opera_from_db(inv.deployment_id, location)

        with xopera_util.cwd(location):
            try:
                if inv.user_id and Settings.secure_workdir:
                    xopera_util.setup_user([location], inv.user_id,
                                           inv.access_token)
                opera_storage = Storage.create(".opera")
                service_template = entry_definitions(location)
                opera_deploy(service_template,
                             inv.inputs,
                             opera_storage,
                             verbose_mode=False,
                             num_workers=inv.workers,
                             delete_existing_state=inv.clean_state)
                outputs = opera_outputs(opera_storage)
                return outputs
            finally:
                if inv.user_id and Settings.secure_workdir:
                    xopera_util.cleanup_user()
Пример #4
0
 def validate(blueprint_id: str, version_tag: str, inputs: dict):
     with tempfile.TemporaryDirectory() as location:
         CSAR_db.get_revision(blueprint_id, location, version_tag)
         try:
             with xopera_util.cwd(location):
                 opera_storage = Storage.create(".opera")
                 service_template = Path(location) / entry_definitions(
                     location)
                 opera_validate(service_template,
                                inputs,
                                opera_storage,
                                verbose=False,
                                executors=False)
             return None
         except Exception as e:
             return "{}: {}".format(
                 e.__class__.__name__,
                 xopera_util.mask_workdir(location, str(e)))
Пример #5
0
 def prepare_location(cls, deployment_id: uuid, location: Path):
     """
     Prepare location with blueprint and session_data (.opera dir)
     """
     inv = PostgreSQL.get_deployment_status(deployment_id)
     if not CSAR_db.get_revision(inv.blueprint_id, location,
                                 inv.version_tag):
         logger.error(
             f'csardb_service.get_revision failed: blueprint_id: {inv.blueprint_id}, '
             f'location: {location}, version_d: {inv.version_id}')
     InvocationService.get_dot_opera_from_db(deployment_id, location)