use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class StackCreatorService method createStack.
public StackResponse createStack(IdentityUser user, StackRequest stackRequest, boolean publicInAccount) throws Exception {
stackRequest.setAccount(user.getAccount());
stackRequest.setOwner(user.getUserId());
stackRequest.setOwnerEmail(user.getUsername());
long start = System.currentTimeMillis();
Stack stack = conversionService.convert(stackRequest, Stack.class);
String stackName = stack.getName();
LOGGER.info("Stack request converted to stack in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
MDCBuilder.buildMdcContext(stack);
start = System.currentTimeMillis();
stack = stackSensitiveDataPropagator.propagate(stackRequest.getCredentialSource(), stack, user);
LOGGER.info("Stack propagated with sensitive data in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
stack = stackDecorator.decorate(stack, stackRequest, user);
LOGGER.info("Stack object has been decorated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
stack.setPublicInAccount(publicInAccount);
start = System.currentTimeMillis();
validateAccountPreferences(stack, user);
LOGGER.info("Account preferences has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
if (stack.getOrchestrator() != null && stack.getOrchestrator().getApiEndpoint() != null) {
stackService.validateOrchestrator(stack.getOrchestrator());
}
for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
templateValidator.validateTemplateRequest(stack.getCredential(), instanceGroup.getTemplate(), stack.getRegion(), stack.getAvailabilityZone(), stack.getPlatformVariant());
}
Blueprint blueprint = null;
if (stackRequest.getClusterRequest() != null) {
start = System.currentTimeMillis();
StackValidationRequest stackValidationRequest = conversionService.convert(stackRequest, StackValidationRequest.class);
LOGGER.info("Stack validation request has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
StackValidation stackValidation = conversionService.convert(stackValidationRequest, StackValidation.class);
LOGGER.info("Stack validation object has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
blueprint = stackValidation.getBlueprint();
start = System.currentTimeMillis();
stackService.validateStack(stackValidation, stackRequest.getClusterRequest().getValidateBlueprint());
LOGGER.info("Stack has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(stack.getCredential());
start = System.currentTimeMillis();
fileSystemValidator.validateFileSystem(stackValidationRequest.getPlatform(), cloudCredential, stackValidationRequest.getFileSystem());
LOGGER.info("Filesystem has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
clusterCreationService.validate(stackRequest.getClusterRequest(), cloudCredential, stack, user);
LOGGER.info("Cluster has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
}
start = System.currentTimeMillis();
stack = stackService.create(user, stack, stackRequest.getImageCatalog(), Optional.ofNullable(stackRequest.getImageId()), Optional.ofNullable(blueprint));
LOGGER.info("Stack object and its dependencies has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
createClusterIfNeed(user, stackRequest, stack, stackName, blueprint);
start = System.currentTimeMillis();
StackResponse response = conversionService.convert(stack, StackResponse.class);
LOGGER.info("Stack response has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
flowManager.triggerProvisioning(stack.getId());
LOGGER.info("Stack provision triggered in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
return response;
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class NetworkConfigurationValidator method validateNetworkForStack.
public boolean validateNetworkForStack(Network network, Iterable<InstanceGroup> instanceGroups) {
if (network.getSubnetCIDR() != null) {
SubnetUtils utils = new SubnetUtils(network.getSubnetCIDR());
int addressCount = utils.getInfo().getAddressCount();
int nodeCount = 0;
for (InstanceGroup instanceGroup : instanceGroups) {
nodeCount += instanceGroup.getNodeCount();
}
if (addressCount < nodeCount) {
LOGGER.error("Cannot assign more than {} addresses in the selected subnet.", addressCount);
throw new BadRequestException(String.format("Cannot assign more than %s addresses in the selected subnet.", addressCount));
}
}
return true;
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class StackDownscaleActions method stackDownscaleCollectResourcesAction.
@Bean(name = "DOWNSCALE_COLLECT_RESOURCES_STATE")
public Action<?, ?> stackDownscaleCollectResourcesAction() {
return new AbstractStackDownscaleAction<StackDownscaleTriggerEvent>(StackDownscaleTriggerEvent.class) {
@Override
protected void doExecute(StackScalingFlowContext context, StackDownscaleTriggerEvent payload, Map<Object, Object> variables) {
stackDownscaleService.startStackDownscale(context, payload);
Stack stack = context.getStack();
LOGGER.debug("Assembling downscale stack event for stack: {}", stack);
List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
variables.put(RESOURCES, resources);
List<CloudInstance> instances = new ArrayList<>();
InstanceGroup group = stack.getInstanceGroupByInstanceGroupName(context.getInstanceGroupName());
for (InstanceMetaData metaData : group.getAllInstanceMetaData()) {
if (context.getInstanceIds().contains(metaData.getInstanceId())) {
CloudInstance cloudInstance = metadataConverter.convert(metaData);
instances.add(cloudInstance);
}
}
variables.put(INSTANCES, instances);
Selectable request = new DownscaleStackCollectResourcesRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), resources, instances);
sendEvent(context.getFlowId(), request);
}
};
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class AccountPreferencesValidatorTest method testValidateShouldNotThrowExceptionWhenTheStackContainsOnlyAllowedInstanceTypes.
@Test
public void testValidateShouldNotThrowExceptionWhenTheStackContainsOnlyAllowedInstanceTypes() throws AccountPreferencesValidationException {
String n1St4Type = "n1-standard-4";
String n1St6Type = "n1-standard-8";
List<String> allowedInstanceTypes = Arrays.asList(n1St4Type, n1St6Type, "n1-standard-16");
when(preferences.getAllowedInstanceTypes()).thenReturn(allowedInstanceTypes);
InstanceGroup cbgateway = Mockito.mock(InstanceGroup.class, Mockito.RETURNS_DEEP_STUBS);
InstanceGroup master = Mockito.mock(InstanceGroup.class, Mockito.RETURNS_DEEP_STUBS);
InstanceGroup slave = Mockito.mock(InstanceGroup.class, Mockito.RETURNS_DEEP_STUBS);
when(cbgateway.getTemplate().getInstanceType()).thenReturn(n1St4Type);
when(master.getTemplate().getInstanceType()).thenReturn(n1St4Type);
when(slave.getTemplate().getInstanceType()).thenReturn(n1St6Type);
when(stack.getInstanceGroups()).thenReturn(Sets.newHashSet(cbgateway, master, slave));
underTest.validate(stack, EMPTY_STRING, EMPTY_STRING);
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class ComponentLocatorServiceTest method createHostGroup.
private HostGroup createHostGroup(String name, String hostname) {
HostGroup hg = new HostGroup();
hg.setName(name);
Constraint constraint = new Constraint();
hg.setConstraint(constraint);
InstanceGroup ig = new InstanceGroup();
constraint.setInstanceGroup(ig);
InstanceMetaData im = new InstanceMetaData();
im.setDiscoveryFQDN(hostname);
ig.setInstanceMetaData(ImmutableSet.of(im));
return hg;
}
Aggregations