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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations