Skip to content

Commit

Permalink
changed "instance" of DevOps/piggyback commands to be of type String
Browse files Browse the repository at this point in the history
* as in K8S this is never an integer, but the pod name

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch-si.com>
  • Loading branch information
thjaeckle committed Apr 29, 2019
1 parent 69537d1 commit 02763d6
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 26 deletions.
Expand Up @@ -152,11 +152,11 @@ private static Route buildRouteWithServiceNameAndInstance(final RequestContext c

return rawPathPrefix(mergeDoubleSlashes().concat(PathMatchers.segment()), instance ->
// /devops/<logging|piggyback>/<serviceName>/<instance>
routeBuilder.build(ctx, serviceName, Integer.parseInt(instance), dittoHeaders)
routeBuilder.build(ctx, serviceName, instance, dittoHeaders)
);
}

private Route routeLogging(final RequestContext ctx, final String serviceName, final Integer instance,
private Route routeLogging(final RequestContext ctx, final String serviceName, final String instance,
final DittoHeaders dittoHeaders) {

return route(
Expand All @@ -180,7 +180,7 @@ private Route routeLogging(final RequestContext ctx, final String serviceName, f
}

private Route routePiggyback(final RequestContext ctx, @Nullable final String serviceName,
@Nullable final Integer instance, final DittoHeaders dittoHeaders) {
@Nullable final String instance, final DittoHeaders dittoHeaders) {
return post(() ->
extractDataBytes(payloadSource ->
handlePerRequest(ctx, dittoHeaders, payloadSource,
Expand All @@ -198,15 +198,16 @@ private Route routePiggyback(final RequestContext ctx, @Nullable final String se
.map(JsonValue::asObject)
.map(DittoHeaders::newBuilder)
.map(head -> head.putHeaders(dittoHeaders))
.map(DittoHeadersBuilder::build)
.map((java.util.function.Function<DittoHeadersBuilder, DittoHeaders>)
DittoHeadersBuilder::build)
.orElse(dittoHeaders));
}
)
)
);
}

private static Function<JsonValue, JsonValue> transformResponse(final String serviceName, final Integer instance) {
private static Function<JsonValue, JsonValue> transformResponse(final String serviceName, final String instance) {
final JsonPointer transformerPointer = transformerPointer(serviceName, instance);
if (transformerPointer.isEmpty()) {
return resp -> resp;
Expand All @@ -218,13 +219,13 @@ private static Function<JsonValue, JsonValue> transformResponse(final String ser
}

private static JsonPointer transformerPointer(@Nullable final String serviceName,
@Nullable final Integer instance) {
@Nullable final String instance) {
JsonPointer newPointer = JsonPointer.empty();
if (serviceName != null) {
newPointer = newPointer.append(JsonPointer.of(serviceName));
}
if (instance != null) {
newPointer = newPointer.append(JsonPointer.of(instance.toString()));
newPointer = newPointer.append(JsonPointer.of(instance));
}
return newPointer;
}
Expand All @@ -239,7 +240,7 @@ private static DittoHeaders createHeaders(final Optional<Long> optionalTimeout)
@FunctionalInterface
private interface RouteBuilderWithOptionalServiceNameAndInstance {

Route build(final RequestContext ctx, final String serviceName, final Integer instance,
Route build(final RequestContext ctx, final String serviceName, final String instance,
final DittoHeaders dittoHeaders);
}

Expand Down
Expand Up @@ -158,7 +158,7 @@ private void handleInitialDevOpsCommand(final DevOpsCommand<?> command) {
final Optional<String> commandServiceNameOpt = command.getServiceName();
if (commandServiceNameOpt.isPresent()) {
final String commandServiceName = commandServiceNameOpt.get();
final Integer commandInstance = command.getInstance().orElse(null);
final String commandInstance = command.getInstance().orElse(null);
if (commandInstance != null) {
topic = command.getType() + ":" + commandServiceName + ":" + commandInstance;
} else {
Expand Down
3 changes: 3 additions & 0 deletions signals/commands/devops/pom.xml
Expand Up @@ -79,6 +79,9 @@
<exclude>org.eclipse.ditto.signals.commands.devops.AggregatedDevOpsCommandResponse#fromJson(java.lang.String,org.eclipse.ditto.model.base.headers.DittoHeaders,java.util.Map)</exclude>
<exclude>org.eclipse.ditto.signals.commands.devops.AggregatedDevOpsCommandResponse#fromJson(org.eclipse.ditto.json.JsonObject,org.eclipse.ditto.model.base.headers.DittoHeaders,java.util.Map)</exclude>
<exclude>org.eclipse.ditto.signals.commands.devops.DevOpsCommandResponseRegistry</exclude>
<exclude>org.eclipse.ditto.signals.commands.devops.ChangeLogLevel</exclude>
<exclude>org.eclipse.ditto.signals.commands.devops.ExecutePiggybackCommand</exclude>
<exclude>org.eclipse.ditto.signals.commands.devops.RetrieveLoggerConfig</exclude>
</excludes>
</parameter>
</configuration>
Expand Down
Expand Up @@ -35,7 +35,7 @@ abstract class AbstractDevOpsCommand<T extends AbstractDevOpsCommand> extends Ab
implements DevOpsCommand<T> {

@Nullable private final String serviceName;
@Nullable private final Integer instance;
@Nullable private final String instance;

/**
* Constructs a new {@code AbstractDevOpsCommand} object.
Expand All @@ -47,7 +47,7 @@ abstract class AbstractDevOpsCommand<T extends AbstractDevOpsCommand> extends Ab
* @throws NullPointerException if any argument is {@code null}.
*/
protected AbstractDevOpsCommand(final String type, @Nullable final String serviceName,
@Nullable final Integer instance, final DittoHeaders dittoHeaders) {
@Nullable final String instance, final DittoHeaders dittoHeaders) {
super(type, dittoHeaders);
this.serviceName = serviceName;
this.instance = instance;
Expand All @@ -57,7 +57,7 @@ public Optional<String> getServiceName() {
return Optional.ofNullable(serviceName);
}

public Optional<Integer> getInstance() {
public Optional<String> getInstance() {
return Optional.ofNullable(instance);
}

Expand Down
Expand Up @@ -57,7 +57,7 @@ public final class ChangeLogLevel extends AbstractDevOpsCommand<ChangeLogLevel>

private final LoggerConfig loggerConfig;

private ChangeLogLevel(@Nullable final String serviceName, @Nullable final Integer instance,
private ChangeLogLevel(@Nullable final String serviceName, @Nullable final String instance,
final LoggerConfig loggerConfig, final DittoHeaders dittoHeaders) {
super(TYPE, serviceName, instance, dittoHeaders);
this.loggerConfig = requireNonNull(loggerConfig, "The logger configuration must not be null!");
Expand All @@ -73,7 +73,7 @@ private ChangeLogLevel(@Nullable final String serviceName, @Nullable final Integ
* @return a new ChangeLogLevel command.
* @throws NullPointerException if any argument is {@code null}.
*/
public static ChangeLogLevel of(@Nullable final String serviceName, @Nullable final Integer instance,
public static ChangeLogLevel of(@Nullable final String serviceName, @Nullable final String instance,
final LoggerConfig loggerConfig, final DittoHeaders dittoHeaders) {
return new ChangeLogLevel(serviceName, instance, loggerConfig, dittoHeaders);
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public static ChangeLogLevel fromJson(final String jsonString, final DittoHeader
public static ChangeLogLevel fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) {
return new CommandJsonDeserializer<ChangeLogLevel>(TYPE, jsonObject).deserialize(() -> {
final String serviceName = jsonObject.getValue(DevOpsCommand.JsonFields.JSON_SERVICE_NAME).orElse(null);
final Integer instance = jsonObject.getValue(DevOpsCommand.JsonFields.JSON_INSTANCE).orElse(null);
final String instance = jsonObject.getValue(DevOpsCommand.JsonFields.JSON_INSTANCE).orElse(null);
final JsonObject loggerConfigJsonObject = jsonObject.getValueOrThrow(JSON_LOGGER_CONFIG);
final LoggerConfig loggerConfig = ImmutableLoggerConfig.fromJson(loggerConfigJsonObject);

Expand Down
Expand Up @@ -77,7 +77,7 @@ default JsonPointer getResourcePath() {
/**
* @return the instance index of the serviceName to which to send the DevOpsCommand.
*/
Optional<Integer> getInstance();
Optional<String> getInstance();

/**
* An enumeration of the known {@link org.eclipse.ditto.json.JsonField}s of a DevOpsCommand.
Expand All @@ -94,8 +94,8 @@ class JsonFields extends Command.JsonFields {
/**
* JSON field containing the instance index of the serviceName serviceName to which to send the DevOpsCommand.
*/
public static final JsonFieldDefinition<Integer> JSON_INSTANCE =
JsonFactory.newIntFieldDefinition("instance", FieldType.REGULAR, JsonSchemaVersion.V_1,
public static final JsonFieldDefinition<String> JSON_INSTANCE =
JsonFactory.newStringFieldDefinition("instance", FieldType.REGULAR, JsonSchemaVersion.V_1,
JsonSchemaVersion.V_2);

}
Expand Down
Expand Up @@ -73,7 +73,7 @@ public final class ExecutePiggybackCommand extends AbstractDevOpsCommand<Execute
private final String targetActorSelection;
private final JsonObject piggybackCommand;

private ExecutePiggybackCommand(@Nullable final String serviceName, @Nullable final Integer instance,
private ExecutePiggybackCommand(@Nullable final String serviceName, @Nullable final String instance,
final String targetActorSelection, final JsonObject piggybackCommand, final DittoHeaders dittoHeaders) {
super(TYPE, serviceName, instance, dittoHeaders);
this.targetActorSelection = requireNonNull(targetActorSelection, "The targetActorSelection must not be null!");
Expand All @@ -91,7 +91,7 @@ private ExecutePiggybackCommand(@Nullable final String serviceName, @Nullable fi
* @return a new ChangeLogLevel command.
* @throws NullPointerException if any argument is {@code null}.
*/
public static ExecutePiggybackCommand of(@Nullable final String serviceName, @Nullable final Integer instance,
public static ExecutePiggybackCommand of(@Nullable final String serviceName, @Nullable final String instance,
final String targetActorSelection, final JsonObject piggybackCommand, final DittoHeaders dittoHeaders) {
return new ExecutePiggybackCommand(serviceName, instance, targetActorSelection, piggybackCommand, dittoHeaders);
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public static ExecutePiggybackCommand fromJson(final String jsonString, final Di
public static ExecutePiggybackCommand fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) {
return new CommandJsonDeserializer<ExecutePiggybackCommand>(TYPE, jsonObject).deserialize(() -> {
final String serviceName = jsonObject.getValue(DevOpsCommand.JsonFields.JSON_SERVICE_NAME).orElse(null);
final Integer instance = jsonObject.getValue(DevOpsCommand.JsonFields.JSON_INSTANCE).orElse(null);
final String instance = jsonObject.getValue(DevOpsCommand.JsonFields.JSON_INSTANCE).orElse(null);
final String targetActorSelection = jsonObject.getValueOrThrow(JSON_TARGET_ACTORSELECTION);
final JsonObject piggybackCommand = jsonObject.getValueOrThrow(JSON_PIGGYBACK_COMMAND);

Expand Down
Expand Up @@ -65,7 +65,7 @@ public final class RetrieveLoggerConfig extends AbstractDevOpsCommand<RetrieveLo
private final boolean allKnownLoggers;
private final List<String> specificLoggers;

private RetrieveLoggerConfig(@Nullable final String serviceName, @Nullable final Integer instance,
private RetrieveLoggerConfig(@Nullable final String serviceName, @Nullable final String instance,
final boolean allKnownLoggers, final List<String> specificLoggers, final DittoHeaders dittoHeaders) {
super(TYPE, serviceName, instance, dittoHeaders);
this.allKnownLoggers = allKnownLoggers;
Expand Down Expand Up @@ -103,7 +103,7 @@ public static RetrieveLoggerConfig ofAllKnownLoggers(@Nullable final String serv
* @return a new RetrieveLoggerConfig command.
*/
public static RetrieveLoggerConfig ofAllKnownLoggers(@Nullable final String serviceName,
@Nullable final Integer instance,
@Nullable final String instance,
final DittoHeaders dittoHeaders) {
return new RetrieveLoggerConfig(serviceName, instance, true, Collections.emptyList(), dittoHeaders);
}
Expand Down Expand Up @@ -154,7 +154,7 @@ public static RetrieveLoggerConfig of(@Nullable final String serviceName, final
* @param specificLoggers one or more loggers to be retrieved.
* @return a new RetrieveLoggerConfig command.
*/
public static RetrieveLoggerConfig of(@Nullable final String serviceName, @Nullable final Integer instance,
public static RetrieveLoggerConfig of(@Nullable final String serviceName, @Nullable final String instance,
final DittoHeaders dittoHeaders, final String... specificLoggers) {
return new RetrieveLoggerConfig(serviceName, instance, false,
specificLoggers == null ? Collections.emptyList() : Arrays.asList(specificLoggers), dittoHeaders);
Expand Down Expand Up @@ -182,7 +182,7 @@ public static RetrieveLoggerConfig of(@Nullable final String serviceName, final
* @param specificLoggers one or more loggers to be retrieved.
* @return a new RetrieveLoggerConfig command.
*/
public static RetrieveLoggerConfig of(@Nullable final String serviceName, @Nullable final Integer instance,
public static RetrieveLoggerConfig of(@Nullable final String serviceName, @Nullable final String instance,
final DittoHeaders dittoHeaders,
final List<String> specificLoggers) {
return new RetrieveLoggerConfig(serviceName, instance, false, specificLoggers, dittoHeaders);
Expand Down Expand Up @@ -215,7 +215,7 @@ public static RetrieveLoggerConfig fromJson(final String jsonString, final Ditto
public static RetrieveLoggerConfig fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) {
return new CommandJsonDeserializer<RetrieveLoggerConfig>(TYPE, jsonObject).deserialize(() -> {
final String serviceName = jsonObject.getValue(DevOpsCommand.JsonFields.JSON_SERVICE_NAME).orElse(null);
final Integer instance = jsonObject.getValue(DevOpsCommand.JsonFields.JSON_INSTANCE).orElse(null);
final String instance = jsonObject.getValue(DevOpsCommand.JsonFields.JSON_INSTANCE).orElse(null);
final boolean isAllKnownLoggers = jsonObject.getValueOrThrow(JSON_ALL_KNOWN_LOGGERS);

if (isAllKnownLoggers) {
Expand Down

0 comments on commit 02763d6

Please sign in to comment.