예제 #1
0
    def _internal_staged_post_snapshot(self, request):
        """Post Snapshot Wrapper for staged plugins.

        Executed after creating a snapshot. This plugin
        operation is run after creating a snapshot for a staged source.

        Run post-snapshot operation for a staged source.

        Args:
           request (StagedPostSnapshotRequest): Post Snapshot arguments.

        Returns:
            StagedPostSnapshotResponse: A response containing the return value
                StagedPostSnapshotResult which has the snapshot metadata on
                success. In case of errors, response object will contain
                PluginErrorResult.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import RepositoryDefinition
        from generated.definitions import LinkedSourceDefinition
        from generated.definitions import SourceConfigDefinition
        from generated.definitions import SnapshotDefinition
        from generated.definitions import SnapshotParametersDefinition

        def to_protobuf(snapshot):
            parameters = common_pb2.PluginDefinedObject()
            parameters.json = json.dumps(snapshot.to_dict())
            snapshot_protobuf = common_pb2.Snapshot()
            snapshot_protobuf.parameters.CopyFrom(parameters)
            return snapshot_protobuf

        if not self.post_snapshot_impl:
            raise OperationNotDefinedError(Op.LINKED_POST_SNAPSHOT)

        staged_source_definition = LinkedSourceDefinition.from_dict(
            json.loads(request.staged_source.linked_source.parameters.json))
        mount = Mount(
            remote_environment=RemoteEnvironment.from_proto(
                request.staged_source.staged_mount.remote_environment),
            mount_path=request.staged_source.staged_mount.mount_path,
            shared_path=request.staged_source.staged_mount.shared_path)
        staged_source = StagedSource(
            guid=request.staged_source.linked_source.guid,
            source_connection=RemoteConnection.from_proto(
                request.staged_source.source_connection),
            parameters=staged_source_definition,
            mount=mount,
            staged_connection=RemoteConnection.from_proto(
                request.staged_source.staged_connection))

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))
        snapshot_parameters = SnapshotParametersDefinition.from_dict(
            json.loads(request.snapshot_parameters.parameters.json))

        snapshot = self.post_snapshot_impl(
            staged_source=staged_source,
            repository=repository,
            source_config=source_config,
            snapshot_parameters=snapshot_parameters)

        # Validate that this is a SnapshotDefinition object
        if not isinstance(snapshot, SnapshotDefinition):
            raise IncorrectReturnTypeError(Op.LINKED_POST_SNAPSHOT,
                                           type(snapshot), SnapshotDefinition)

        response = platform_pb2.StagedPostSnapshotResponse()
        response.return_value.snapshot.CopyFrom(to_protobuf(snapshot))

        return response
예제 #2
0
    def _internal_direct_post_snapshot(self, request):
        """Post Snapshot Wrapper for direct plugins.

        Executed after creating a snapshot. This plugin
        operation is run after creating a snapshot for a direct source.

        Run post-snapshot operation for a direct source.

        Args:
           request (DirectPostSnapshotRequest): Post Snapshot arguments.

        Returns:
           DirectPostSnapshotResponse: A response containing the return value -
           DirectPostSnapshotResult which has the snapshot metadata on success.
           In case of errors, response object will contain PluginErrorResult.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import RepositoryDefinition
        from generated.definitions import LinkedSourceDefinition
        from generated.definitions import SourceConfigDefinition
        from generated.definitions import SnapshotDefinition
        from generated.definitions import SnapshotParametersDefinition

        def to_protobuf(snapshot):
            parameters = common_pb2.PluginDefinedObject()
            parameters.json = json.dumps(snapshot.to_dict())
            snapshot_protobuf = common_pb2.Snapshot()
            snapshot_protobuf.parameters.CopyFrom(parameters)
            return snapshot_protobuf

        if not self.post_snapshot_impl:
            raise OperationNotDefinedError(Op.LINKED_POST_SNAPSHOT)

        direct_source_definition = LinkedSourceDefinition.from_dict(
            json.loads(request.direct_source.linked_source.parameters.json))
        direct_source = DirectSource(
            guid=request.direct_source.linked_source.guid,
            connection=RemoteConnection.from_proto(
                request.direct_source.connection),
            parameters=direct_source_definition)

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))
        snap_params = json.loads(request.snapshot_parameters.parameters.json)
        #
        # The snapshot_parameters object should be set to None if the json from
        # the protobuf is None to differentiate no snapshot parameters vs empty
        # snapshot parameters.
        #
        snapshot_parameters = (
            None if snap_params is None else
            SnapshotParametersDefinition.from_dict(snap_params))

        snapshot = self.post_snapshot_impl(
            direct_source=direct_source,
            repository=repository,
            source_config=source_config,
            optional_snapshot_parameters=snapshot_parameters)

        # Validate that this is a SnapshotDefinition object
        if not isinstance(snapshot, SnapshotDefinition):
            raise IncorrectReturnTypeError(Op.LINKED_POST_SNAPSHOT,
                                           type(snapshot), SnapshotDefinition)

        direct_post_snapshot_response = (
            platform_pb2.DirectPostSnapshotResponse())
        direct_post_snapshot_response.return_value.snapshot.CopyFrom(
            to_protobuf(snapshot))

        return direct_post_snapshot_response
예제 #3
0
    def _internal_staged_pre_snapshot(self, request):
        """Pre Snapshot Wrapper for staged plugins.

        Executed before creating a snapshot. This plugin
        operation is run prior to creating a snapshot for a staged source.

        Run pre-snapshot operation for a staged source.

        Args:
            request (StagedPreSnapshotRequest): Pre Snapshot arguments.

        Returns:
            StagedPreSnapshotResponse: A response containing
                StagedPreSnapshotResult if successful or PluginErrorResult
                in case of an error.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import RepositoryDefinition
        from generated.definitions import LinkedSourceDefinition
        from generated.definitions import SourceConfigDefinition
        from generated.definitions import SnapshotParametersDefinition

        #
        # While linked.pre_snapshot() is not a required operation, this should
        # not be called if it wasn't implemented.
        #
        if not self.pre_snapshot_impl:
            raise OperationNotDefinedError(Op.LINKED_PRE_SNAPSHOT)

        linked_source = request.staged_source.linked_source
        staged_source_definition = (LinkedSourceDefinition.from_dict(
            json.loads(linked_source.parameters.json)))
        staged_mount = request.staged_source.staged_mount
        mount = Mount(remote_environment=RemoteEnvironment.from_proto(
            staged_mount.remote_environment),
                      mount_path=staged_mount.mount_path,
                      shared_path=staged_mount.shared_path)
        staged_source = StagedSource(
            guid=linked_source.guid,
            source_connection=RemoteConnection.from_proto(
                request.staged_source.source_connection),
            parameters=staged_source_definition,
            mount=mount,
            staged_connection=RemoteConnection.from_proto(
                request.staged_source.staged_connection))

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))
        snapshot_parameters = SnapshotParametersDefinition.from_dict(
            json.loads(request.snapshot_parameters.parameters.json))

        self.pre_snapshot_impl(staged_source=staged_source,
                               repository=repository,
                               source_config=source_config,
                               snapshot_parameters=snapshot_parameters)

        response = platform_pb2.StagedPreSnapshotResponse()
        response.return_value.CopyFrom(platform_pb2.StagedPreSnapshotResult())

        return response
예제 #4
0
    def _internal_direct_pre_snapshot(self, request):
        """Pre Snapshot Wrapper for direct plugins.

        Executed before creating a snapshot. This plugin
        operation is run prior to creating a snapshot for a direct source.

        Run pre-snapshot operation for a direct source.

        Args:
           request (DirectPreSnapshotRequest): Pre Snapshot arguments.

        Returns:
           DirectPreSnapshotResponse: A response containing
           DirectPreSnapshotResult if successful or PluginErrorResult in case
           of an error.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import RepositoryDefinition
        from generated.definitions import LinkedSourceDefinition
        from generated.definitions import SourceConfigDefinition
        from generated.definitions import SnapshotParametersDefinition

        #
        # While linked.pre_snapshot() is not a required operation, this should
        # not be called if it wasn't implemented.
        #
        if not self.pre_snapshot_impl:
            raise OperationNotDefinedError(Op.LINKED_PRE_SNAPSHOT)

        direct_source_definition = LinkedSourceDefinition.from_dict(
            json.loads(request.direct_source.linked_source.parameters.json))
        direct_source = DirectSource(
            guid=request.direct_source.linked_source.guid,
            connection=RemoteConnection.from_proto(
                request.direct_source.connection),
            parameters=direct_source_definition)

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))
        snap_params = json.loads(request.snapshot_parameters.parameters.json)
        #
        # The snapshot_parameters object should be set to None if the json from
        # the protobuf is None to differentiate no snapshot parameters vs empty
        # snapshot parameters.
        #
        snapshot_parameters = (
            None if snap_params is None else
            SnapshotParametersDefinition.from_dict(snap_params))

        self.pre_snapshot_impl(
            direct_source=direct_source,
            repository=repository,
            source_config=source_config,
            optional_snapshot_parameters=snapshot_parameters)

        direct_pre_snapshot_response = platform_pb2.DirectPreSnapshotResponse()
        direct_pre_snapshot_response.return_value.CopyFrom(
            platform_pb2.DirectPreSnapshotResult())

        return direct_pre_snapshot_response