use of io.gravitee.cockpit.api.command.bridge.BridgeReply in project gravitee-management-rest-api by gravitee-io.
the class BridgeCommandHandlerTest method shouldNotHandleUnknownOperation.
@Test
public void shouldNotHandleUnknownOperation() {
BridgeCommand command = new BridgeCommand();
command.setOperation("UNKWOWN_OPERATION");
TestObserver<BridgeReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR) && reply.getMessage().equals("No handler found for this operation: UNKWOWN_OPERATION"));
}
use of io.gravitee.cockpit.api.command.bridge.BridgeReply in project gravitee-management-rest-api by gravitee-io.
the class BridgeCommandHandlerTest method shouldHandleListEnvironmentsOperation.
@Test
public void shouldHandleListEnvironmentsOperation() {
BridgeCommand command = new BridgeCommand();
command.setOperation(BridgeOperation.LIST_ENVIRONMENT.name());
command.setId("command-id");
cut = new BridgeCommandHandler(Arrays.asList(new TestingFakeListEnvironmentOperationHandler(), new AnotherTestingFakeOperationHandler()));
TestObserver<BridgeReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED) && reply.getMessage().equals("Fake operation handler"));
}
use of io.gravitee.cockpit.api.command.bridge.BridgeReply in project gravitee-management-rest-api by gravitee-io.
the class ProcessPromotionOperationHandlerTest method shouldHandlePromotionRequestIfCannotReadPromotionEntity.
@Test
public void shouldHandlePromotionRequestIfCannotReadPromotionEntity() throws JsonProcessingException {
BridgeCommand command = new BridgeCommand();
command.setOperation(BridgeOperation.PROMOTE_API.name());
command.setId(COMMAND_ID);
command.setInstallationId(INSTALLATION_ID);
command.setOrganizationId(ORGANIZATION_ID);
command.setEnvironmentId(ENVIRONMENT_ID);
command.setPayload(new BridgePayload());
final BridgeTarget bridgeTarget = new BridgeTarget();
bridgeTarget.setEnvironmentId("source");
command.setTarget(bridgeTarget);
when(objectMapper.readValue(command.getPayload().getContent(), PromotionEntity.class)).thenThrow(JsonMappingException.class);
// When
TestObserver<BridgeReply> obs = cut.handle(command).test();
// Then
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR) && reply.getMessage().equals("Problem while deserializing promotion for environment [" + ENVIRONMENT_ID + "]"));
}
use of io.gravitee.cockpit.api.command.bridge.BridgeReply in project gravitee-management-rest-api by gravitee-io.
the class CockpitServiceImpl method listPromotionTargets.
@Override
public CockpitReply<List<PromotionTargetEntity>> listPromotionTargets(String organizationId) {
final BridgeCommand listEnvironmentCommand = this.bridgeCommandFactory.createListEnvironmentCommand();
BridgeReply bridgeReply = cockpitCommandService.send(listEnvironmentCommand);
if (bridgeReply.getCommandStatus() != CommandStatus.SUCCEEDED) {
logger.warn("Problem while listing promotion targets through cockpit. \n {}", bridgeReply.getMessage());
return new CockpitReply<>(Collections.emptyList(), CockpitReplyStatus.ERROR);
}
final List<PromotionTargetEntity> environmentEntities = ((BridgeMultiReply) bridgeReply).getReplies().stream().filter(simpleReply -> CommandStatus.SUCCEEDED == simpleReply.getCommandStatus()).map(simpleReply -> {
try {
final EnvironmentEntity environmentEntity = this.objectMapper.readValue(simpleReply.getPayload(), EnvironmentEntity.class);
// because cockpit has updated them to handle the case were id is "DEFAULT"
return new PromotionTargetEntity(environmentEntity, simpleReply.getOrganizationId(), simpleReply.getEnvironmentId(), simpleReply.getInstallationId());
} catch (JsonProcessingException e) {
logger.warn("Problem while deserializing environment {} with payload {}", simpleReply.getEnvironmentId(), simpleReply.getPayload());
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toList());
return new CockpitReply<>(environmentEntities, CockpitReplyStatus.SUCCEEDED);
}
use of io.gravitee.cockpit.api.command.bridge.BridgeReply in project gravitee-management-rest-api by gravitee-io.
the class CockpitServiceImpl method processPromotion.
@Override
public CockpitReply<PromotionEntity> processPromotion(PromotionEntity promotionEntity) {
String serializedPromotion = null;
try {
serializedPromotion = objectMapper.writeValueAsString(promotionEntity);
} catch (JsonProcessingException e) {
logger.warn("Problem while serializing promotion {}", promotionEntity.getId());
}
final BridgeCommand processPromotionCommand = this.bridgeCommandFactory.createProcessPromotionCommand(promotionEntity.getSourceEnvCockpitId(), serializedPromotion);
final BridgeReply bridgeReply = cockpitCommandService.send(processPromotionCommand);
if (bridgeReply.getCommandStatus() != CommandStatus.SUCCEEDED) {
logger.warn("Problem while processing API promotion request through cockpit. \n {}", bridgeReply.getMessage());
return new CockpitReply<>(null, CockpitReplyStatus.ERROR);
}
return new CockpitReply<>(promotionEntity, CockpitReplyStatus.SUCCEEDED);
}
Aggregations