示例#1
0
    def restore(self, context, restore, restore_auth):
        LOG.info(_LI("Starting restore service:restore action"))

        checkpoint_id = restore["checkpoint_id"]
        provider_id = restore["provider_id"]
        provider = self.provider_registry.show_provider(provider_id)
        try:
            checkpoint_collection = provider.get_checkpoint_collection()
            checkpoint = checkpoint_collection.get(checkpoint_id)
        except Exception:
            LOG.error(_LE("Invalid checkpoint id: %s"), checkpoint_id)
            raise exception.InvalidInput(reason=_("Invalid checkpoint id"))

        if checkpoint.status != constants.CHECKPOINT_STATUS_AVAILABLE:
            raise exception.CheckpointNotAvailable(checkpoint_id=checkpoint_id)

        try:
            restoration_flow = self.worker.get_restoration_flow(
                context, constants.OPERATION_RESTORE, checkpoint, provider,
                restore, restore_auth)
        except Exception:
            LOG.exception(
                _LE("Failed to create restoration flow checkpoint: %s"),
                checkpoint_id)
            raise exception.FlowError(flow="restore",
                                      error=_("Failed to create flow"))
        try:
            self.worker.run_flow(restoration_flow)
        except Exception:
            LOG.exception(_LE("Failed to run restoration flow checkpoint: %s"),
                          checkpoint_id)
            raise exception.FlowError(flow="restore",
                                      error=_("Failed to run flow"))
示例#2
0
    def verification(self, context, verification):
        LOG.info("Starting verify service:verify action")

        checkpoint_id = verification["checkpoint_id"]
        provider_id = verification["provider_id"]
        provider = self.provider_registry.show_provider(provider_id)
        if not provider:
            raise exception.ProviderNotFound(provider_id=provider_id)

        self.validate_verify_parameters(verification, provider)

        checkpoint_collection = provider.get_checkpoint_collection()
        checkpoint = checkpoint_collection.get(checkpoint_id)

        if checkpoint.status != constants.CHECKPOINT_STATUS_AVAILABLE:
            raise exception.CheckpointNotAvailable(checkpoint_id=checkpoint_id)

        try:
            flow = self.worker.get_flow(
                context=context,
                operation_type=constants.OPERATION_VERIFY,
                checkpoint=checkpoint,
                provider=provider,
                verify=verification)
        except Exception:
            LOG.exception("Failed to create verify flow checkpoint: %s",
                          checkpoint_id)
            raise exception.FlowError(flow="verify",
                                      error=_("Failed to create flow"))
        self._spawn(self.worker.run_flow, flow)
示例#3
0
    def restore(self, context, restore, restore_auth):
        LOG.info("Starting restore service:restore action")

        checkpoint_id = restore["checkpoint_id"]
        provider_id = restore["provider_id"]
        provider = self.provider_registry.show_provider(provider_id)
        if not provider:
            raise exception.ProviderNotFound(provider_id=provider_id)

        checkpoint_collection = provider.get_checkpoint_collection()
        checkpoint = checkpoint_collection.get(checkpoint_id)

        if checkpoint.status != constants.CHECKPOINT_STATUS_AVAILABLE:
            raise exception.CheckpointNotAvailable(checkpoint_id=checkpoint_id)

        try:
            flow = self.worker.get_flow(
                context=context,
                operation_type=constants.OPERATION_RESTORE,
                checkpoint=checkpoint,
                provider=provider,
                restore=restore,
                restore_auth=restore_auth)
        except Exception:
            LOG.exception("Failed to create restore flow checkpoint: %s",
                          checkpoint_id)
            raise exception.FlowError(flow="restore",
                                      error=_("Failed to create flow"))
        self._spawn(self.worker.run_flow, flow)
示例#4
0
def create_flows(context, protectable_registry, workflow_engine, plan,
                 provider, checkpoints_protect_copy, checkpoint_collection):
    LOG.debug("Creating flows for the plan. checkpoints: %s",
              checkpoints_protect_copy)
    flow_name = "Copy_flows" + plan.get('id')
    copy_flows = workflow_engine.build_flow(flow_name, 'linear')
    for checkpoint_protect_copy in checkpoints_protect_copy:
        checkpoint_protect_id = checkpoint_protect_copy.get(
            "checkpoint_protect_id")
        checkpoint_copy_id = checkpoint_protect_copy.get("checkpoint_copy_id")
        checkpoint_protect = checkpoint_collection.get(checkpoint_protect_id)
        checkpoint_copy = checkpoint_collection.get(checkpoint_copy_id)
        try:
            copy_flow = get_flow(
                context,
                protectable_registry,
                workflow_engine,
                plan,
                provider,
                checkpoint_protect,
                checkpoint_copy,
            )
        except Exception as e:
            LOG.exception("Failed to create copy flow, checkpoint: %s",
                          checkpoint_protect_id)
            raise exception.FlowError(
                flow="copy",
                error=e.msg if hasattr(e, 'msg') else 'Internal error')
        workflow_engine.add_tasks(copy_flows, copy_flow)
    flows_engine = workflow_engine.get_engine(copy_flows,
                                              store={'context': context})
    LOG.debug("Creating flows for the plan. copy_flows: %s", copy_flows)

    return flows_engine
示例#5
0
    def copy(self, context, plan):
        """create copy of checkpoint for the given plan

        :param plan: Define that protection plan should be done
        """

        LOG.info("Starting protection service:copy action.")
        LOG.debug("Creating the checkpoint copy for the plan: %s", plan)

        if not plan:
            raise exception.InvalidPlan(
                reason=_('The protection plan is None'))
        provider_id = plan.get('provider_id', None)
        plan_id = plan.get('id', None)
        provider = self.provider_registry.show_provider(provider_id)
        checkpoints = None
        checkpoint_collection = provider.get_checkpoint_collection()
        try:
            checkpoints = self.list_checkpoints(context,
                                                provider_id,
                                                filters={'plan_id': plan_id})
        except Exception as e:
            LOG.exception("Failed to get checkpoints for the plan: %s",
                          plan_id)
            exc = exception.FlowError(flow="copy",
                                      error="Failed to get checkpoints")
            six.raise_from(exc, e)
        try:
            flow, checkpoint_copy = self.worker.get_flow(
                context=context,
                protectable_registry=self.protectable_registry,
                operation_type=constants.OPERATION_COPY,
                plan=plan,
                provider=provider,
                checkpoint=checkpoints,
                checkpoint_collection=checkpoint_collection)
        except Exception as e:
            LOG.exception("Failed to create copy flow, plan: %s", plan_id)
            raise exception.FlowError(
                flow="copy",
                error=e.msg if hasattr(e, 'msg') else 'Internal error')
        self._spawn(self.worker.run_flow, flow)
        return checkpoint_copy
示例#6
0
    def protect(self, context, plan, checkpoint_properties=None):
        """create protection for the given plan

        :param plan: Define that protection plan should be done
        """

        LOG.info("Starting protection service:protect action")
        LOG.debug("protecting: %s checkpoint_properties:%s", plan,
                  checkpoint_properties)

        if not plan:
            raise exception.InvalidPlan(
                reason=_('the protection plan is None'))
        provider_id = plan.get('provider_id', None)
        plan_id = plan.get('id', None)
        provider = self.provider_registry.show_provider(provider_id)
        checkpoint_collection = provider.get_checkpoint_collection()
        try:
            checkpoint = checkpoint_collection.create(plan,
                                                      checkpoint_properties,
                                                      context=context)
        except Exception as e:
            LOG.exception("Failed to create checkpoint, plan: %s", plan_id)
            exc = exception.FlowError(flow="protect",
                                      error="Error creating checkpoint")
            six.raise_from(exc, e)
        try:
            flow = self.worker.get_flow(
                context=context,
                protectable_registry=self.protectable_registry,
                operation_type=constants.OPERATION_PROTECT,
                plan=plan,
                provider=provider,
                checkpoint=checkpoint)
        except Exception as e:
            LOG.exception("Failed to create protection flow, plan: %s",
                          plan_id)
            raise exception.FlowError(
                flow="protect",
                error=e.msg if hasattr(e, 'msg') else 'Internal error')
        self._spawn(self.worker.run_flow, flow)
        return checkpoint.id
示例#7
0
    def protect(self, context, plan):
        """create protection for the given plan

        :param plan: Define that protection plan should be done
        """

        LOG.info(_LI("Starting protection service:protect action"))
        LOG.debug("protecting: %s type: %s", plan, type(plan))

        if not plan:
            raise exception.InvalidPlan(
                reason=_('the protection plan is None'))
        provider_id = plan.get('provider_id', None)
        plan_id = plan.get('id', None)
        provider = self.provider_registry.show_provider(provider_id)
        try:
            protection_flow = self.worker.get_flow(context,
                                                   constants.OPERATION_PROTECT,
                                                   plan=plan,
                                                   provider=provider)
        except Exception:
            LOG.exception(_LE("Failed to create protection flow, plan: %s"),
                          plan_id)
            raise exception.FlowError(flow="protect",
                                      error=_("Failed to create flow"))
        try:
            self.worker.run_flow(protection_flow)
        except Exception:
            LOG.exception(_LE("Failed to run protection flow, plan: %s"),
                          plan_id)

            raise exception.FlowError(flow="protect",
                                      error=_("Failed to run flow"))
        finally:
            checkpoint = self.worker.flow_outputs(protection_flow,
                                                  target='checkpoint')
            return {'checkpoint_id': checkpoint.id}