Search in sources :

Example 6 with BridgeReply

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"));
}
Also used : BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 7 with BridgeReply

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"));
}
Also used : BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 8 with BridgeReply

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 + "]"));
}
Also used : BridgePayload(io.gravitee.cockpit.api.command.bridge.BridgePayload) BridgeTarget(io.gravitee.cockpit.api.command.bridge.BridgeTarget) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 9 with BridgeReply

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);
}
Also used : Logger(org.slf4j.Logger) BridgeCommandFactory(io.gravitee.rest.api.service.cockpit.command.bridge.BridgeCommandFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) BridgeMultiReply(io.gravitee.cockpit.api.command.bridge.BridgeMultiReply) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Objects(java.util.Objects) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) List(java.util.List) Component(org.springframework.stereotype.Component) CommandStatus(io.gravitee.cockpit.api.command.CommandStatus) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) CockpitCommandService(io.gravitee.rest.api.service.cockpit.command.CockpitCommandService) Collections(java.util.Collections) PromotionTargetEntity(io.gravitee.rest.api.model.promotion.PromotionTargetEntity) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) PromotionTargetEntity(io.gravitee.rest.api.model.promotion.PromotionTargetEntity) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply)

Example 10 with BridgeReply

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);
}
Also used : BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply)

Aggregations

BridgeReply (io.gravitee.cockpit.api.command.bridge.BridgeReply)16 BridgeCommand (io.gravitee.cockpit.api.command.bridge.BridgeCommand)14 Test (org.junit.Test)13 BridgePayload (io.gravitee.cockpit.api.command.bridge.BridgePayload)7 BridgeTarget (io.gravitee.cockpit.api.command.bridge.BridgeTarget)7 BridgeSimpleReply (io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply)5 InstallationEntity (io.gravitee.rest.api.model.InstallationEntity)5 PromotionEntity (io.gravitee.rest.api.model.promotion.PromotionEntity)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 BridgeMultiReply (io.gravitee.cockpit.api.command.bridge.BridgeMultiReply)2 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CommandStatus (io.gravitee.cockpit.api.command.CommandStatus)1 PromotionTargetEntity (io.gravitee.rest.api.model.promotion.PromotionTargetEntity)1 CockpitCommandService (io.gravitee.rest.api.service.cockpit.command.CockpitCommandService)1 BridgeCommandFactory (io.gravitee.rest.api.service.cockpit.command.bridge.BridgeCommandFactory)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1