@Override public PurgeNamespace setDittoHeaders(final DittoHeaders dittoHeaders) { if (Objects.equals(getDittoHeaders(), dittoHeaders)) { return this; } return new PurgeNamespace(getNamespace(), dittoHeaders); }
private void purgeNamespace(final PurgeNamespace purgeNamespace) { LogUtil.enhanceLogWithCorrelationId(log, purgeNamespace); final Collection<S> namespaceSelections = selectNamespace(purgeNamespace.getNamespace()); log.info("Running <{}>. Affected collections: <{}>.", purgeNamespace, namespaceSelections); final ActorRef sender = getSender(); namespaceOps.purgeAll(namespaceSelections) .runWith(Sink.head(), materializer) .thenAccept(errors -> { // send response to speed up purge workflow final PurgeNamespaceResponse response; if (errors.isEmpty()) { response = PurgeNamespaceResponse.successful(purgeNamespace.getNamespace(), getResourceType(), purgeNamespace.getDittoHeaders()); } else { LogUtil.enhanceLogWithCorrelationId(log, purgeNamespace); final String namespace = purgeNamespace.getNamespace(); errors.forEach(error -> log.error(error, "Error purging namespace <{}>", namespace)); response = PurgeNamespaceResponse.failed(namespace, getResourceType(), purgeNamespace.getDittoHeaders()); } sender.tell(response, getSelf()); }) .exceptionally(error -> { LogUtil.enhanceLogWithCorrelationId(log, purgeNamespace); log.error(error, "Failed to purge namespace <{}>!", purgeNamespace.getNamespace()); // Reply nothing - DB errors were converted to stream elements and handled return null; }); }
/** * Returns an instance of {@code PurgeNamespace}. * * @param namespace the namespace to be purged. * @param dittoHeaders the headers of the command. * @return the instance. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code namespace} is empty. */ public static PurgeNamespace of(final CharSequence namespace, final DittoHeaders dittoHeaders) { return new PurgeNamespace(namespace, dittoHeaders); }
underTest.tell(PurgeNamespace.of(purgedNamespace, dittoHeaders), getRef()); expectMsg(PurgeNamespaceResponse.successful(purgedNamespace, getResourceType(), dittoHeaders));
/** * Creates a new {@code PurgeNamespace} from a JSON object. * * @param jsonObject the JSON object of which the PurgeNamespace is to be created. * @param dittoHeaders the headers. * @return the command. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonMissingFieldException if {@code jsonObject} did not contain * {@link org.eclipse.ditto.signals.commands.namespaces.NamespaceCommand.JsonFields#NAMESPACE}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static PurgeNamespace fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<PurgeNamespace>(TYPE, jsonObject).deserialize(() -> { final String namespace = jsonObject.getValueOrThrow(NamespaceCommand.JsonFields.NAMESPACE); return new PurgeNamespace(namespace, dittoHeaders); }); }