use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class StackToStackDetailsConverter method convert.
public StackDetails convert(Stack source) {
StackDetails stackDetails = new StackDetails();
stackDetails.setId(source.getId());
stackDetails.setName(source.getName());
stackDetails.setTunnel(source.getTunnel().name());
stackDetails.setRegion(source.getRegion());
stackDetails.setAvailabilityZone(source.getAvailabilityZone());
stackDetails.setCloudPlatform(source.getCloudPlatform());
stackDetails.setPlatformVariant(source.getPlatformvariant());
StackStatus stackStatus = source.getStackStatus();
if (stackStatus != null) {
stackDetails.setStatus(stackStatus.getStatusString());
stackDetails.setDetailedStatus(stackStatus.getDetailedStackStatusString());
stackDetails.setStatusReason(stackStatus.getStatusReason());
}
Set<InstanceGroup> instanceGroups = instanceGroupService.findByStackId(source.getId());
stackDetails.setMultiAz(getMultiAz(instanceGroups));
stackDetails.setInstanceGroups(instanceGroups.stream().map(e -> instanceGroupToInstanceGroupDetailsConverter.convert(e)).collect(Collectors.toList()));
stackDetails.setTags(source.getTags());
convertImage(stackDetails, source);
return stackDetails;
}
use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class CreateFreeIpaRequestToStackConverter method extendGatewaySecurityGroupWithDefaultGatewayCidrs.
private void extendGatewaySecurityGroupWithDefaultGatewayCidrs(Stack stack) {
Set<InstanceGroup> gateways = stack.getInstanceGroups().stream().filter(ig -> InstanceGroupType.MASTER == ig.getInstanceGroupType()).collect(Collectors.toSet());
Set<String> defaultGatewayCidrs = defaultGatewayCidr.stream().filter(StringUtils::isNotBlank).collect(Collectors.toSet());
if (!defaultGatewayCidrs.isEmpty() && !stack.getTunnel().useCcm()) {
for (InstanceGroup gateway : gateways) {
if (gateway.getSecurityGroup() != null && CollectionUtils.isEmpty(gateway.getSecurityGroup().getSecurityGroupIds())) {
Set<SecurityRule> rules = gateway.getSecurityGroup().getSecurityRules();
defaultGatewayCidrs.forEach(cloudbreakCidr -> rules.add(createSecurityRule(gateway.getSecurityGroup(), cloudbreakCidr, stack.getGatewayport().toString())));
LOGGER.info("The control plane cidrs {} are added to the {} gateway group for the {} port.", defaultGatewayCidrs, gateway.getGroupName(), stack.getGatewayport());
}
}
}
}
use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class InstanceMetaDataToCloudInstanceConverter method convert.
public CloudInstance convert(InstanceMetaData metaDataEntity) {
InstanceGroup group = metaDataEntity.getInstanceGroup();
Optional<StackAuthenticationView> stackAuthenticationView = instanceMetaDataService.getStackAuthenticationViewByInstanceMetaDataId(metaDataEntity.getId());
Template template = metaDataEntity.getInstanceGroup().getTemplate();
Optional<StackAuthentication> stackAuthentication = stackAuthenticationView.map(StackAuthenticationView::getStackAuthentication);
InstanceStatus status = getInstanceStatus(metaDataEntity);
String imageId = stackAuthenticationView.map(StackAuthenticationView::getStackId).map(stackId -> imageService.getByStackId(stackId)).map(ImageEntity::getImageName).orElse(null);
InstanceTemplate instanceTemplate = stackToCloudStackConverter.buildInstanceTemplate(template, group.getGroupName(), metaDataEntity.getPrivateId(), status, imageId);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication(stackAuthentication.map(StackAuthentication::getPublicKey).orElse(null), stackAuthentication.map(StackAuthentication::getPublicKeyId).orElse(null), stackAuthentication.map(StackAuthentication::getLoginUserName).orElse(null));
Map<String, Object> params = new HashMap<>();
params.put(SUBNET_ID, metaDataEntity.getSubnetId());
params.put(CloudInstance.INSTANCE_NAME, metaDataEntity.getInstanceName());
Stack stack = stackAuthenticationView.map(StackAuthenticationView::getStackId).map(stackService::getStackById).orElseThrow(NotFoundException::new);
Map<String, Object> cloudInstanceParameters = stackToCloudStackConverter.buildCloudInstanceParameters(stack.getEnvironmentCrn(), metaDataEntity);
params.putAll(cloudInstanceParameters);
return new CloudInstance(metaDataEntity.getInstanceId(), instanceTemplate, instanceAuthentication, metaDataEntity.getSubnetId(), stack.getAvailabilityZone(), params);
}
use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method updateMetadataAction.
@Bean(name = "UPSCALE_UPDATE_METADATA_STATE")
public Action<?, ?> updateMetadataAction() {
return new AbstractUpscaleAction<>(PostInstallFreeIpaSuccess.class) {
@Override
protected void doExecute(StackContext context, PostInstallFreeIpaSuccess payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Upscale update metadata");
if (!isRepair(variables)) {
int nodeCount = getInstanceCountByGroup(variables);
for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
instanceGroup.setNodeCount(nodeCount);
instanceGroupService.save(instanceGroup);
}
}
sendEvent(context, UPSCALE_UPDATE_METADATA_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
}
};
}
use of com.sequenceiq.freeipa.entity.InstanceGroup in project cloudbreak by hortonworks.
the class FreeIpaUpscaleActions method addInstancesAction.
@Bean(name = "UPSCALE_ADD_INSTANCES_STATE")
public Action<?, ?> addInstancesAction() {
return new AbstractUpscaleAction<>(StackEvent.class) {
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Adding instances");
List<CloudInstance> newInstances = buildNewInstances(context.getStack(), getInstanceCountByGroup(variables));
if (newInstances.isEmpty()) {
skipAddingNewInstances(context, stack);
} else {
addNewInstances(context, stack, newInstances);
}
}
private void skipAddingNewInstances(StackContext context, Stack stack) {
List<CloudResourceStatus> list = resourceService.getAllAsCloudResourceStatus(stack.getId());
UpscaleStackRequest<UpscaleStackResult> request = new UpscaleStackRequest<>(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), ResourceLists.transform(list), new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 0L));
UpscaleStackResult result = new UpscaleStackResult(request.getResourceId(), ResourceStatus.CREATED, list);
sendEvent(context, result.selector(), result);
}
private void addNewInstances(StackContext context, Stack stack, List<CloudInstance> newInstances) {
Stack updatedStack = instanceMetaDataService.saveInstanceAndGetUpdatedStack(stack, newInstances);
List<CloudResource> cloudResources = resourceService.findAllByStackId(stack.getId()).stream().map(resource -> resourceConverter.convert(resource)).collect(Collectors.toList());
CloudStack updatedCloudStack = cloudStackConverter.convert(updatedStack);
UpscaleStackRequest<UpscaleStackResult> request = new UpscaleStackRequest<>(context.getCloudContext(), context.getCloudCredential(), updatedCloudStack, cloudResources, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, (long) newInstances.size()));
sendEvent(context, request.selector(), request);
}
private List<CloudInstance> buildNewInstances(Stack stack, int instanceCountByGroup) {
long privateId = privateIdProvider.getFirstValidPrivateId(stack.getInstanceGroups());
List<CloudInstance> newInstances = new ArrayList<>();
for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
int remainingInstances = instanceCountByGroup - instanceGroup.getNotDeletedInstanceMetaDataSet().size();
for (long i = 0; i < remainingInstances; ++i) {
newInstances.add(cloudStackConverter.buildInstance(stack, null, instanceGroup, stack.getStackAuthentication(), privateId++, InstanceStatus.CREATE_REQUESTED));
}
}
return newInstances;
}
};
}
Aggregations