use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.
the class StackCreationService method updateNodeCount.
private void updateNodeCount(Long stackId, Iterable<Group> originalGroups, Iterable<CloudResourceStatus> statuses) {
for (Group group : originalGroups) {
int nodeCount = group.getInstancesSize();
List<CloudResourceStatus> failedResources = removeFailedMetadata(stackId, statuses, group);
if (!failedResources.isEmpty()) {
int failedCount = failedResources.size();
InstanceGroup instanceGroup = instanceGroupRepository.findOneByGroupNameInStack(stackId, group.getName());
instanceGroup.setNodeCount(nodeCount - failedCount);
instanceGroupRepository.save(instanceGroup);
flowMessageService.fireEventAndLog(stackId, Msg.STACK_INFRASTRUCTURE_ROLLBACK_MESSAGE, UPDATE_IN_PROGRESS.name(), failedCount, group.getName(), failedResources.get(0).getStatusReason());
}
}
}
use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.
the class YarnResourceConnector method launch.
@Override
public List<CloudResourceStatus> launch(AuthenticatedContext authenticatedContext, CloudStack stack, PersistenceNotifier persistenceNotifier, AdjustmentType adjustmentType, Long threshold) throws Exception {
CreateApplicationRequest createApplicationRequest = new CreateApplicationRequest();
createApplicationRequest.setName(createApplicationName(authenticatedContext));
createApplicationRequest.setQueue(stack.getParameters().getOrDefault(YarnConstants.YARN_QUEUE_PARAMETER, defaultQueue));
String lifeTimeStr = stack.getParameters().get(YarnConstants.YARN_LIFETIME_PARAMETER);
createApplicationRequest.setLifetime(lifeTimeStr != null ? Integer.parseInt(lifeTimeStr) : defaultLifeTime);
Artifact artifact = new Artifact();
artifact.setId(stack.getImage().getImageName());
artifact.setType("DOCKER");
List<YarnComponent> components = new ArrayList<>();
for (Group group : stack.getGroups()) {
YarnComponent component = new YarnComponent();
component.setName(group.getName());
component.setNumberOfContainers(group.getInstancesSize());
String userData = stack.getImage().getUserDataByType(group.getType());
component.setLaunchCommand(String.format("/bootstrap/start-systemd '%s' '%s' '%s'", Base64.getEncoder().encodeToString(userData.getBytes()), stack.getLoginUserName(), stack.getPublicKey()));
component.setArtifact(artifact);
component.setDependencies(new ArrayList<>());
InstanceTemplate instanceTemplate = group.getReferenceInstanceConfiguration().getTemplate();
Resource resource = new Resource();
resource.setCpus(instanceTemplate.getParameter(PlatformParametersConsts.CUSTOM_INSTANCETYPE_CPUS, Integer.class));
resource.setMemory(instanceTemplate.getParameter(PlatformParametersConsts.CUSTOM_INSTANCETYPE_MEMORY, Integer.class));
component.setResource(resource);
component.setRunPrivilegedContainer(true);
Configuration configuration = new Configuration();
Map<String, String> propsMap = Maps.newHashMap();
propsMap.put("conf.cb-conf.per.component", "true");
propsMap.put("site.cb-conf.userData", '\'' + Base64.getEncoder().encodeToString(userData.getBytes()) + '\'');
propsMap.put("site.cb-conf.sshUser", '\'' + stack.getLoginUserName() + '\'');
propsMap.put("site.cb-conf.groupname", '\'' + group.getName() + '\'');
propsMap.put("site.cb-conf.sshPubKey", '\'' + stack.getPublicKey() + '\'');
configuration.setProperties(propsMap);
ConfigFile configFileProps = new ConfigFile();
configFileProps.setType(ConfigFileType.PROPERTIES.name());
configFileProps.setSrcFile("cb-conf");
configFileProps.setDestFile("/etc/cloudbreak-config.props");
configuration.setFiles(Collections.singletonList(configFileProps));
component.setConfiguration(configuration);
components.add(component);
}
createApplicationRequest.setComponents(components);
CloudResource yarnApplication = new Builder().type(YARN_APPLICATION).name(createApplicationRequest.getName()).build();
persistenceNotifier.notifyAllocation(yarnApplication, authenticatedContext.getCloudContext());
YarnClient yarnClient = yarnClientUtil.createYarnClient(authenticatedContext);
ResponseContext responseContext = yarnClient.createApplication(createApplicationRequest);
if (responseContext.getResponseError() != null) {
ApplicationErrorResponse applicationErrorResponse = responseContext.getResponseError();
throw new CloudConnectorException(String.format("Yarn Application creation error: HTTP Return: %d Error: %s", responseContext.getStatusCode(), applicationErrorResponse.getDiagnostics()));
}
return check(authenticatedContext, Collections.singletonList(yarnApplication));
}
use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method buildInstanceGroups.
public List<Group> buildInstanceGroups(List<InstanceGroup> instanceGroups, StackAuthentication stackAuthentication, Collection<String> deleteRequests) {
// sort by name to avoid shuffling the different instance groups
Collections.sort(instanceGroups);
List<Group> groups = new ArrayList<>();
long privateId = getFirstValidPrivateId(instanceGroups);
for (InstanceGroup instanceGroup : instanceGroups) {
if (instanceGroup.getTemplate() != null) {
CloudInstance skeleton = null;
List<CloudInstance> instances = new ArrayList<>();
Template template = instanceGroup.getTemplate();
int desiredNodeCount = instanceGroup.getNodeCount();
// existing instances
for (InstanceMetaData metaData : instanceGroup.getInstanceMetaData()) {
InstanceStatus status = getInstanceStatus(metaData, deleteRequests);
instances.add(buildInstance(metaData, template, stackAuthentication, instanceGroup.getGroupName(), metaData.getPrivateId(), status));
}
// new instances
int existingNodesSize = instances.size();
if (existingNodesSize < desiredNodeCount) {
for (long i = 0; i < desiredNodeCount - existingNodesSize; i++) {
instances.add(buildInstance(null, template, stackAuthentication, instanceGroup.getGroupName(), privateId++, InstanceStatus.CREATE_REQUESTED));
}
}
if (existingNodesSize == desiredNodeCount && desiredNodeCount == 0) {
skeleton = buildInstance(null, template, stackAuthentication, instanceGroup.getGroupName(), 0L, InstanceStatus.CREATE_REQUESTED);
}
Json attributes = instanceGroup.getAttributes();
InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stackAuthentication);
Map<String, Object> fields = attributes == null ? Collections.emptyMap() : attributes.getMap();
groups.add(new Group(instanceGroup.getGroupName(), instanceGroup.getInstanceGroupType(), instances, buildSecurity(instanceGroup), skeleton, fields, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
}
}
return groups;
}
use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method buildInstances.
public List<CloudInstance> buildInstances(Stack stack) {
List<Group> groups = buildInstanceGroups(stack.getInstanceGroupsAsList(), stack.getStackAuthentication(), Collections.emptySet());
List<CloudInstance> cloudInstances = new ArrayList<>();
for (Group group : groups) {
cloudInstances.addAll(group.getInstances());
}
return cloudInstances;
}
use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.
the class InstanceMetadataService method saveInstanceRequests.
public void saveInstanceRequests(Stack stack, Iterable<Group> groups) {
Set<InstanceGroup> instanceGroups = stack.getInstanceGroups();
for (Group group : groups) {
InstanceGroup instanceGroup = getInstanceGroup(instanceGroups, group.getName());
List<InstanceMetaData> existingInGroup = instanceMetaDataRepository.findAllByInstanceGroupAndInstanceStatus(instanceGroup, com.sequenceiq.cloudbreak.api.model.InstanceStatus.REQUESTED);
for (CloudInstance cloudInstance : group.getInstances()) {
InstanceTemplate instanceTemplate = cloudInstance.getTemplate();
boolean exists = existingInGroup.stream().anyMatch(i -> i.getPrivateId().equals(instanceTemplate.getPrivateId()));
if (InstanceStatus.CREATE_REQUESTED == instanceTemplate.getStatus() && !exists) {
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setPrivateId(instanceTemplate.getPrivateId());
instanceMetaData.setInstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus.REQUESTED);
instanceMetaData.setInstanceGroup(instanceGroup);
instanceMetaDataRepository.save(instanceMetaData);
}
}
}
}
Aggregations