Search in sources :

Example 11 with BridgeCommand

use of io.gravitee.cockpit.api.command.bridge.BridgeCommand in project gravitee-management-rest-api by gravitee-io.

the class BridgeCommandFactory method createPromoteApiCommand.

public BridgeCommand createPromoteApiCommand(String targetEnvironmentId, String serializedPromotion) {
    BridgeCommand createPromoteApiCommand = initBridgeCommand();
    createPromoteApiCommand.setOperation(BridgeOperation.PROMOTE_API.name());
    BridgePayload payload = new BridgePayload();
    payload.setContent(serializedPromotion);
    createPromoteApiCommand.setPayload(payload);
    BridgeTarget target = new BridgeTarget();
    target.setScopes(Collections.singletonList(BRIDGE_SCOPE_APIM));
    target.setEnvironmentId(targetEnvironmentId);
    createPromoteApiCommand.setTarget(target);
    return createPromoteApiCommand;
}
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)

Example 12 with BridgeCommand

use of io.gravitee.cockpit.api.command.bridge.BridgeCommand in project gravitee-management-rest-api by gravitee-io.

the class BridgeCommandFactory method createProcessPromotionCommand.

public BridgeCommand createProcessPromotionCommand(String sourceEnvCockpitId, String serializedPromotion) {
    BridgeCommand processPromotionCommand = initBridgeCommand();
    processPromotionCommand.setOperation(BridgeOperation.PROCESS_API_PROMOTION.name());
    BridgePayload payload = new BridgePayload();
    payload.setContent(serializedPromotion);
    processPromotionCommand.setPayload(payload);
    BridgeTarget target = new BridgeTarget();
    target.setScopes(Collections.singletonList(BRIDGE_SCOPE_APIM));
    target.setEnvironmentId(sourceEnvCockpitId);
    processPromotionCommand.setTarget(target);
    return processPromotionCommand;
}
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)

Example 13 with BridgeCommand

use of io.gravitee.cockpit.api.command.bridge.BridgeCommand 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 14 with BridgeCommand

use of io.gravitee.cockpit.api.command.bridge.BridgeCommand 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)

Example 15 with BridgeCommand

use of io.gravitee.cockpit.api.command.bridge.BridgeCommand in project gravitee-management-rest-api by gravitee-io.

the class CockpitServiceImpl method requestPromotion.

@Override
public CockpitReply<PromotionEntity> requestPromotion(PromotionEntity promotionEntity) {
    String serializedPromotion = null;
    try {
        serializedPromotion = objectMapper.writeValueAsString(promotionEntity);
    } catch (JsonProcessingException e) {
        logger.warn("Problem while serializing promotion {}", promotionEntity.getId());
    }
    final BridgeCommand promoteApiCommand = this.bridgeCommandFactory.createPromoteApiCommand(promotionEntity.getTargetEnvCockpitId(), serializedPromotion);
    BridgeReply bridgeReply = cockpitCommandService.send(promoteApiCommand);
    if (bridgeReply.getCommandStatus() != CommandStatus.SUCCEEDED) {
        logger.warn("Problem while sending 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

BridgeCommand (io.gravitee.cockpit.api.command.bridge.BridgeCommand)20 BridgeReply (io.gravitee.cockpit.api.command.bridge.BridgeReply)14 Test (org.junit.Test)13 BridgeTarget (io.gravitee.cockpit.api.command.bridge.BridgeTarget)12 BridgePayload (io.gravitee.cockpit.api.command.bridge.BridgePayload)9 InstallationEntity (io.gravitee.rest.api.model.InstallationEntity)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 PromotionEntity (io.gravitee.rest.api.model.promotion.PromotionEntity)4 BridgeSimpleReply (io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply)3 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