use of com.sequenceiq.cloudbreak.domain.ClusterComponent in project cloudbreak by hortonworks.
the class AmbariClusterServiceTest method setup.
@Before
public void setup() throws CloudbreakException {
Cluster cluster = new Cluster();
cluster.setId(1L);
cluster.setBlueprint(new Blueprint());
cluster.getBlueprint().setId(1L);
Stack stack = new Stack();
stack.setOrchestrator(new Orchestrator());
stack.setCluster(cluster);
when(clusterRepository.findById(any(Long.class))).thenReturn(cluster);
when(stackService.getByIdWithLists(any(Long.class))).thenReturn(stack);
when(orchestratorTypeResolver.resolveType(any(Orchestrator.class))).thenReturn(OrchestratorType.HOST);
when(orchestratorTypeResolver.resolveType(anyString())).thenReturn(OrchestratorType.HOST);
when(clusterComponentConfigProvider.getHDPRepo(any(Long.class))).thenReturn(new StackRepoDetails());
when(clusterComponentConfigProvider.store(any(ClusterComponent.class))).thenAnswer(invocation -> invocation.getArgumentAt(0, ClusterComponent.class));
when(clusterComponentConfigProvider.getComponent(any(Long.class), any(ComponentType.class))).thenReturn(new ClusterComponent());
when(blueprintService.get(any(Long.class))).thenReturn(cluster.getBlueprint());
}
use of com.sequenceiq.cloudbreak.domain.ClusterComponent in project cloudbreak by hortonworks.
the class ClusterCreationSetupService method prepare.
public Cluster prepare(ClusterRequest request, Stack stack, Blueprint blueprint, IdentityUser user) throws Exception {
String stackName = stack.getName();
long start = System.currentTimeMillis();
Cluster cluster = conversionService.convert(request, Cluster.class);
cluster.setStack(stack);
LOGGER.info("Cluster conversion took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
cluster = clusterDecorator.decorate(cluster, request, blueprint, user, stack);
LOGGER.info("Cluster object decorated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
List<ClusterComponent> components = new ArrayList<>();
Set<Component> allComponent = componentConfigProvider.getAllComponentsByStackIdAndType(stack.getId(), Sets.newHashSet(ComponentType.AMBARI_REPO_DETAILS, ComponentType.HDP_REPO_DETAILS, ComponentType.IMAGE));
Optional<Component> stackAmbariRepoConfig = allComponent.stream().filter(c -> c.getComponentType().equals(ComponentType.AMBARI_REPO_DETAILS) && c.getName().equalsIgnoreCase(ComponentType.AMBARI_REPO_DETAILS.name())).findAny();
Optional<Component> stackHdpRepoConfig = allComponent.stream().filter(c -> c.getComponentType().equals(ComponentType.HDP_REPO_DETAILS) && c.getName().equalsIgnoreCase(ComponentType.HDP_REPO_DETAILS.name())).findAny();
Optional<Component> stackImageComponent = allComponent.stream().filter(c -> c.getComponentType().equals(ComponentType.IMAGE) && c.getName().equalsIgnoreCase(ComponentType.IMAGE.name())).findAny();
ClusterComponent ambariRepoConfig = determineAmbariRepoConfig(stackAmbariRepoConfig, request.getAmbariRepoDetailsJson(), stackImageComponent, cluster);
components.add(ambariRepoConfig);
ClusterComponent hdpRepoConfig = determineHDPRepoConfig(blueprint, stack.getId(), stackHdpRepoConfig, request, cluster, user, stackImageComponent);
components.add(hdpRepoConfig);
checkVDFFile(ambariRepoConfig, hdpRepoConfig, stackName);
LOGGER.info("Cluster components saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
Cluster savedCluster = clusterService.create(user, stack, cluster, components);
LOGGER.info("Cluster object creation took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
return savedCluster;
}
use of com.sequenceiq.cloudbreak.domain.ClusterComponent in project cloudbreak by hortonworks.
the class ClusterCreationSetupService method determineHDPRepoConfig.
private ClusterComponent determineHDPRepoConfig(Blueprint blueprint, long stackId, Optional<Component> stackHdpRepoConfig, ClusterRequest request, Cluster cluster, IdentityUser user, Optional<Component> stackImageComponent) throws JsonProcessingException {
Json stackRepoDetailsJson;
if (!stackHdpRepoConfig.isPresent()) {
AmbariStackDetailsJson ambariStackDetails = request.getAmbariStackDetails();
if (ambariStackDetails != null) {
setOsTypeFromImageIfMissing(cluster, stackImageComponent, ambariStackDetails);
StackRepoDetails stackRepoDetails = conversionService.convert(ambariStackDetails, StackRepoDetails.class);
stackRepoDetailsJson = new Json(stackRepoDetails);
} else {
StackRepoDetails stackRepoDetails = SerializationUtils.clone(defaultHDPInfo(blueprint, request, user).getRepo());
Optional<String> vdfUrl = getVDFUrlByOsType(stackId, stackRepoDetails);
vdfUrl.ifPresent(s -> stackRepoDetails.getStack().put(CUSTOM_VDF_REPO_KEY, s));
stackRepoDetailsJson = new Json(stackRepoDetails);
}
} else {
stackRepoDetailsJson = stackHdpRepoConfig.get().getAttributes();
}
return new ClusterComponent(ComponentType.HDP_REPO_DETAILS, stackRepoDetailsJson, cluster);
}
use of com.sequenceiq.cloudbreak.domain.ClusterComponent in project cloudbreak by hortonworks.
the class AmbariClusterService method upgrade.
@Override
public void upgrade(Long stackId, AmbariRepo ambariRepoUpgrade) {
if (ambariRepoUpgrade != null) {
Stack stack = stackService.getByIdWithLists(stackId);
Cluster cluster = clusterRepository.findById(stack.getCluster().getId());
if (cluster == null) {
throw new BadRequestException(String.format("Cluster does not exist on stack with '%s' id.", stackId));
}
if (!stack.isAvailable()) {
throw new BadRequestException(String.format("Stack '%s' is currently in '%s' state. Upgrade requests to a cluster can only be made if the underlying stack is 'AVAILABLE'.", stackId, stack.getStatus()));
}
if (!cluster.isAvailable()) {
throw new BadRequestException(String.format("Cluster '%s' is currently in '%s' state. Upgrade requests to a cluster can only be made if the underlying stack is 'AVAILABLE'.", stackId, stack.getStatus()));
}
AmbariRepo ambariRepo = clusterComponentConfigProvider.getAmbariRepo(cluster.getId());
if (ambariRepo == null) {
try {
clusterComponentConfigProvider.store(new ClusterComponent(ComponentType.AMBARI_REPO_DETAILS, new Json(ambariRepoUpgrade), stack.getCluster()));
} catch (JsonProcessingException ignored) {
throw new BadRequestException(String.format("Ambari repo details cannot be saved. %s", ambariRepoUpgrade));
}
} else {
ClusterComponent component = clusterComponentConfigProvider.getComponent(cluster.getId(), ComponentType.AMBARI_REPO_DETAILS);
ambariRepo.setBaseUrl(ambariRepoUpgrade.getBaseUrl());
ambariRepo.setGpgKeyUrl(ambariRepoUpgrade.getGpgKeyUrl());
ambariRepo.setPredefined(false);
ambariRepo.setVersion(ambariRepoUpgrade.getVersion());
try {
component.setAttributes(new Json(ambariRepo));
clusterComponentConfigProvider.store(component);
} catch (JsonProcessingException ignored) {
throw new BadRequestException(String.format("Ambari repo details cannot be saved. %s", ambariRepoUpgrade));
}
}
try {
flowManager.triggerClusterUpgrade(stack.getId());
} catch (RuntimeException e) {
throw new CloudbreakServiceException(e);
}
}
}
use of com.sequenceiq.cloudbreak.domain.ClusterComponent in project cloudbreak by hortonworks.
the class ClusterComponentConfigProvider method store.
public ClusterComponent store(ClusterComponent component) {
LOGGER.debug("Component is going to be saved: {}", component);
ClusterComponent ret = componentRepository.save(component);
LOGGER.debug("Component saved: stackId: {}, component: {}", ret.getCluster().getId(), ret);
return ret;
}
Aggregations