Skip to content

Commit

Permalink
review:
Browse files Browse the repository at this point in the history
* some minor renamings
* removed RetrieveMongoStatus + CheckHealth (they were not used)
* renamed RetrieveMongoStatusResponse to CurrentMongoStatus as this is not a response, but generated on-the-fly

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch-si.com>
  • Loading branch information
thjaeckle committed Jul 12, 2019
1 parent 8c05026 commit 250813b
Show file tree
Hide file tree
Showing 22 changed files with 210 additions and 296 deletions.
Expand Up @@ -539,7 +539,7 @@ Response example:

Send a cleanup command by piggyback to the entity's service and shard region to trigger removal of stale events and
snapshots manually. Here is an example for things. Change the service name and shard region name accordingly for
policies and connections. Typically `INSTANCE_INDEX=1`.
policies and connections. Typically in a docker based environment, use `INSTANCE_INDEX=1`.


`POST /devops/piggygack/things/<INSTANCE_INDEX>?timeout=10000`
Expand All @@ -551,7 +551,7 @@ policies and connections. Typically `INSTANCE_INDEX=1`.
"aggregate": false
},
"piggybackCommand": {
"type": "cleanup.commands:cleanup",
"type": "cleanup.commands:cleanupPersistence",
"entityId": "ditto:thing1"
}
}
Expand All @@ -563,7 +563,7 @@ Response example:
{
"?": {
"?": {
"type": "cleanup.responses:cleanup",
"type": "cleanup.responses:cleanupPersistence",
"status": 200,
"entityId": "thing:ditto:thing1"
}
Expand Down
@@ -1,97 +1,97 @@
/*
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.services.base.actors;

import static org.eclipse.ditto.model.base.common.ConditionChecker.argumentNotEmpty;
import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull;

import org.eclipse.ditto.model.namespaces.NamespaceReader;
import org.eclipse.ditto.signals.commands.common.Shutdown;
import org.eclipse.ditto.signals.commands.common.ShutdownReason;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import akka.actor.ActorRef;
import akka.actor.PoisonPill;
import akka.cluster.pubsub.DistributedPubSubMediator;
import akka.japi.pf.ReceiveBuilder;

/**
* Responsible for shutting down the given actor in case a shutdown command contains a reason that is applicable for
* the information hold by this behaviour.
*/
public final class ShutdownBehaviour {

private static final Logger LOG = LoggerFactory.getLogger(ShutdownBehaviour.class);

private final String namespace;
private final String entityId;

private final ActorRef self;

private ShutdownBehaviour(final String namespace, final String entityId, final ActorRef self) {
this.namespace = namespace;
this.entityId = entityId;
this.self = self;
}

/**
* Create the actor behavior from its entity ID and reference.
*
* @param entityId entity ID to react to.
* @param pubSubMediator Akka pub-sub mediator.
* @param self reference of the actor itself.
* @return the actor behavior.
*/
public static ShutdownBehaviour fromId(final String entityId, final ActorRef pubSubMediator,
final ActorRef self) {

argumentNotEmpty(entityId, "Entity ID");
checkNotNull(self, "Self");

final String namespace = NamespaceReader.fromEntityId(entityId).orElse("");

final ShutdownBehaviour purgeEntitiesBehaviour = new ShutdownBehaviour(namespace, entityId, self);

purgeEntitiesBehaviour.subscribePubSub(checkNotNull(pubSubMediator, "Pub-Sub-Mediator"));
return purgeEntitiesBehaviour;
}

private void subscribePubSub(final ActorRef pubSubMediator) {
pubSubMediator.tell(new DistributedPubSubMediator.Subscribe(Shutdown.TYPE, self), self);
}

/**
* Create a new receive builder matching on messages handled by this actor.
*
* @return new receive builder.
*/
public ReceiveBuilder createReceive() {
return ReceiveBuilder.create()
.match(Shutdown.class, this::shutdown)
.match(DistributedPubSubMediator.SubscribeAck.class, this::subscribeAck);
}

private void shutdown(final Shutdown shutdown) {
final ShutdownReason shutdownReason = shutdown.getReason();

if(shutdownReason.isRelevantFor(namespace) || shutdownReason.isRelevantFor(entityId)) {
LOG.info("Shutting down <{}> due to <{}>.", self, shutdown);
self.tell(PoisonPill.getInstance(), ActorRef.noSender());
}
}

private void subscribeAck(final DistributedPubSubMediator.SubscribeAck ack) {
// do nothing
}
}
/*
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.services.base.actors;

import static org.eclipse.ditto.model.base.common.ConditionChecker.argumentNotEmpty;
import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull;

import org.eclipse.ditto.model.namespaces.NamespaceReader;
import org.eclipse.ditto.signals.commands.common.Shutdown;
import org.eclipse.ditto.signals.commands.common.ShutdownReason;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import akka.actor.ActorRef;
import akka.actor.PoisonPill;
import akka.cluster.pubsub.DistributedPubSubMediator;
import akka.japi.pf.ReceiveBuilder;

/**
* Responsible for shutting down the given actor in case a shutdown command contains a reason that is applicable for the
* information hold by this behaviour.
*/
public final class ShutdownBehaviour {

private static final Logger LOG = LoggerFactory.getLogger(ShutdownBehaviour.class);

private final String namespace;
private final String entityId;

private final ActorRef self;

private ShutdownBehaviour(final String namespace, final String entityId, final ActorRef self) {
this.namespace = namespace;
this.entityId = entityId;
this.self = self;
}

/**
* Create the actor behavior from its entity ID and reference.
*
* @param entityId entity ID to react to.
* @param pubSubMediator Akka pub-sub mediator.
* @param self reference of the actor itself.
* @return the actor behavior.
*/
public static ShutdownBehaviour fromId(final String entityId, final ActorRef pubSubMediator,
final ActorRef self) {

argumentNotEmpty(entityId, "Entity ID");
checkNotNull(self, "Self");

final String namespace = NamespaceReader.fromEntityId(entityId).orElse("");

final ShutdownBehaviour purgeEntitiesBehaviour = new ShutdownBehaviour(namespace, entityId, self);

purgeEntitiesBehaviour.subscribePubSub(checkNotNull(pubSubMediator, "Pub-Sub-Mediator"));
return purgeEntitiesBehaviour;
}

private void subscribePubSub(final ActorRef pubSubMediator) {
pubSubMediator.tell(new DistributedPubSubMediator.Subscribe(Shutdown.TYPE, self), self);
}

/**
* Create a new receive builder matching on messages handled by this actor.
*
* @return new receive builder.
*/
public ReceiveBuilder createReceive() {
return ReceiveBuilder.create()
.match(Shutdown.class, this::shutdown)
.match(DistributedPubSubMediator.SubscribeAck.class, this::subscribeAck);
}

private void shutdown(final Shutdown shutdown) {
final ShutdownReason shutdownReason = shutdown.getReason();

if (shutdownReason.isRelevantFor(namespace) || shutdownReason.isRelevantFor(entityId)) {
LOG.info("Shutting down <{}> due to <{}>.", self, shutdown);
self.tell(PoisonPill.getInstance(), ActorRef.noSender());
}
}

private void subscribeAck(final DistributedPubSubMediator.SubscribeAck ack) {
// do nothing
}
}

This file was deleted.

Expand Up @@ -20,6 +20,8 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.annotation.concurrent.Immutable;

import akka.actor.ActorRef;
import akka.actor.Cancellable;
import akka.actor.Props;
Expand Down Expand Up @@ -151,4 +153,22 @@ private void pollHealth() {
childActor.tell(RetrieveHealth.newInstance(), getSelf()));
}

/**
* Internal command to check the health of underlying systems.
*/
@Immutable
private static final class CheckHealth {

private CheckHealth() {
}

/**
* Returns a new {@code CheckHealth} instance.
*
* @return the new CheckHealth instance.
*/
public static CheckHealth newInstance() {
return new CheckHealth();
}
}
}
Expand Up @@ -35,7 +35,7 @@ public final class RetrieveHealth extends AbstractCommand<RetrieveHealth> {
/**
* Type prefix of this command.
*/
public static final String TYPE_PREFIX = "status.commands:";
public static final String TYPE_PREFIX = "status." + TYPE_QUALIFIER + ":";

/**
* Name of this command.
Expand Down Expand Up @@ -110,4 +110,10 @@ public String getResourceType() {
// no resource type
return "";
}

@Override
public String toString() {
return getClass().getSimpleName() + " [" + super.toString() + "]";
}

}
Expand Up @@ -39,7 +39,7 @@ public final class RetrieveHealthResponse extends AbstractCommandResponse<Retrie
/**
* Type of this response.
*/
public static final String TYPE = "status.responses:" + RetrieveHealth.NAME;
public static final String TYPE = "status." + TYPE_QUALIFIER + ":" + RetrieveHealth.NAME;

/**
* Json field of the StatusInfo-payload.
Expand Down Expand Up @@ -130,7 +130,7 @@ public int hashCode() {

@Override
public String toString() {
return "RetrieveHealthResponse[statusInfo=" + statusInfo + ", dittoHeaders=" + getDittoHeaders() + "]";
return getClass().getSimpleName() + " [" + super.toString() + ", statusInfo=" + statusInfo + "]";
}

private static HttpStatusCode toHttpStatusCode(final StatusInfo.Status status) {
Expand Down
Expand Up @@ -12,39 +12,37 @@
*/
package org.eclipse.ditto.services.utils.health.mongo;

import java.io.Serializable;
import java.util.Objects;
import java.util.Optional;

import javax.annotation.concurrent.Immutable;

/**
* Response to the {@link RetrieveMongoStatus} command.
* Reflects the currently determined MongoDB health status.
* Whether {@code alive} or not including a description.
*/
@Immutable
public final class RetrieveMongoStatusResponse implements Serializable {

private static final long serialVersionUID = 1L;
public final class CurrentMongoStatus {

private final boolean alive;
private final String description;

/**
* Constructs a new {@code RetrieveMongoStatusResponse} object.
* Constructs a new {@code CurrentMongoStatus} object.
*
* @param alive indicates whether the Persistence is alive.
*/
public RetrieveMongoStatusResponse(final boolean alive) {
public CurrentMongoStatus(final boolean alive) {
this(alive, null);
}

/**
* Constructs a new {@code RetrieveMongoStatusResponse} object.
* Constructs a new {@code CurrentMongoStatus} object.
*
* @param alive indicates whether the Persistence is alive.
* @param description an optional description why it is alive/not alive.
*/
public RetrieveMongoStatusResponse(final boolean alive, final String description) {
public CurrentMongoStatus(final boolean alive, final String description) {
this.alive = alive;
this.description = description;
}
Expand Down Expand Up @@ -75,7 +73,7 @@ public boolean equals(final Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
final RetrieveMongoStatusResponse that = (RetrieveMongoStatusResponse) o;
final CurrentMongoStatus that = (CurrentMongoStatus) o;
return alive == that.alive && Objects.equals(description, that.description);
}

Expand Down

0 comments on commit 250813b

Please sign in to comment.