use of com.sequenceiq.cloudbreak.domain.Container in project cloudbreak by hortonworks.
the class AmbariDecommissioner method removeHostsFromOrchestrator.
private PollingResult removeHostsFromOrchestrator(Stack stack, AmbariClient ambariClient, List<String> hostNames) throws CloudbreakException {
Orchestrator orchestrator = stack.getOrchestrator();
Map<String, Object> map = new HashMap<>(orchestrator.getAttributes().getMap());
OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(orchestrator.getType());
try {
if (orchestratorType.containerOrchestrator()) {
OrchestrationCredential credential = new OrchestrationCredential(orchestrator.getApiEndpoint(), map);
ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
Set<Container> containers = containerRepository.findContainersInCluster(stack.getCluster().getId());
List<ContainerInfo> containersToDelete = containers.stream().filter(input -> hostNames.contains(input.getHost()) && input.getImage().contains(AMBARI_AGENT.getName())).map(input -> new ContainerInfo(input.getContainerId(), input.getName(), input.getHost(), input.getImage())).collect(Collectors.toList());
containerOrchestrator.deleteContainer(containersToDelete, credential);
containerRepository.delete(containers);
return waitForHostsToLeave(stack, ambariClient, hostNames);
} else if (orchestratorType.hostOrchestrator()) {
HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
Map<String, String> privateIpsByFQDN = new HashMap<>();
stack.getInstanceMetaDataAsList().stream().filter(instanceMetaData -> hostNames.stream().anyMatch(hn -> hn.contains(instanceMetaData.getDiscoveryFQDN().split("\\.")[0]))).forEach(instanceMetaData -> privateIpsByFQDN.put(instanceMetaData.getDiscoveryFQDN(), instanceMetaData.getPrivateIp()));
List<GatewayConfig> allGatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
hostOrchestrator.tearDown(allGatewayConfigs, privateIpsByFQDN);
}
} catch (CloudbreakOrchestratorException e) {
LOGGER.error("Failed to delete orchestrator components while decommissioning: ", e);
throw new CloudbreakException("Failed to delete orchestrator components while decommissioning: ", e);
}
return SUCCESS;
}
use of com.sequenceiq.cloudbreak.domain.Container in project cloudbreak by hortonworks.
the class ClusterTerminationService method deleteClusterContainers.
public Boolean deleteClusterContainers(Cluster cluster) {
try {
Orchestrator orchestrator = cluster.getStack().getOrchestrator();
ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
try {
Map<String, Object> map = new HashMap<>(orchestrator.getAttributes().getMap());
OrchestrationCredential credential = new OrchestrationCredential(orchestrator.getApiEndpoint(), map);
Set<Container> containers = containerRepository.findContainersInCluster(cluster.getId());
List<ContainerInfo> containerInfo = containers.stream().map(c -> new ContainerInfo(c.getContainerId(), c.getName(), c.getHost(), c.getImage())).collect(Collectors.toList());
containerOrchestrator.deleteContainer(containerInfo, credential);
containerRepository.delete(containers);
deleteClusterHostGroupsWithItsMetadata(cluster);
} catch (CloudbreakOrchestratorException e) {
throw new TerminationFailedException(String.format("Failed to delete containers of cluster (id:'%s',name:'%s').", cluster.getId(), cluster.getName()), e);
}
return Boolean.TRUE;
} catch (CloudbreakException ignored) {
return Boolean.FALSE;
}
}
use of com.sequenceiq.cloudbreak.domain.Container in project cloudbreak by hortonworks.
the class ContainerInfoToContainerConverter method convert.
@Override
public Container convert(ContainerInfo source) {
Container container = new Container();
container.setContainerId(source.getId());
container.setName(source.getName());
container.setImage(source.getImage());
container.setHost(source.getHost());
return container;
}
use of com.sequenceiq.cloudbreak.domain.Container in project cloudbreak by hortonworks.
the class ClusterContainerRunnerTest method runNewNodesClusterContainersWhenContainerRunnerFailed.
@Test
public void runNewNodesClusterContainersWhenContainerRunnerFailed() throws CloudbreakException {
Stack stack = TestUtil.stack();
Cluster cluster = TestUtil.cluster(TestUtil.blueprint(), stack, 1L);
stack.setCluster(cluster);
HostGroupAdjustmentJson hostGroupAdjustment = new HostGroupAdjustmentJson();
hostGroupAdjustment.setHostGroup("agent");
when(containerOrchestratorResolver.get(anyString())).thenReturn(new FailedMockContainerOrchestrator());
when(clusterService.retrieveClusterByStackId(anyLong())).thenReturn(cluster);
thrown.expect(CloudbreakException.class);
thrown.expectMessage("com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException: failed");
Set<Container> containers = new HashSet<>();
Container ambariServer = new Container();
ambariServer.setName("server");
ambariServer.setImage(DockerContainer.AMBARI_SERVER.getName());
ambariServer.setHost("hostname-1");
ambariServer.setContainerId("1");
Container ambariAgent = new Container();
ambariAgent.setName("agent");
ambariAgent.setImage(DockerContainer.AMBARI_AGENT.getName());
ambariAgent.setHost("hostname-2");
ambariAgent.setContainerId("1");
containers.add(ambariAgent);
containers.add(ambariServer);
when(containerService.findContainersInCluster(anyLong())).thenReturn(containers);
when(hostGroupRepository.findHostGroupInClusterByName(anyLong(), anyString())).thenReturn(TestUtil.hostGroup());
when(stackRepository.findOneWithLists(anyLong())).thenReturn(stack);
when(tlsSecurityService.buildGatewayConfig(anyLong(), any(InstanceMetaData.class), anyInt(), any(), any())).thenReturn(new GatewayConfig("10.0.0.1", "198.0.0.1", "10.0.0.1", 8443, false));
when(instanceMetaDataRepository.findAliveInstancesInInstanceGroup(anyLong())).thenReturn(new ArrayList<>());
when(containerService.save(anyList())).thenReturn(new ArrayList<>());
when(constraintFactory.getAmbariAgentConstraint(ambariServer.getHost(), null, stack.cloudPlatform(), TestUtil.hostGroup(), hostGroupAdjustment.getScalingAdjustment(), new ArrayList<>(), "")).thenReturn(new Builder().build());
underTest.addClusterContainers(stack.getId(), hostGroupAdjustment.getHostGroup(), hostGroupAdjustment.getScalingAdjustment());
}
use of com.sequenceiq.cloudbreak.domain.Container in project cloudbreak by hortonworks.
the class ClusterContainerRunnerTest method runNewNodesClusterContainersWhenContainerRunnerCancelled.
@Test(expected = CancellationException.class)
public void runNewNodesClusterContainersWhenContainerRunnerCancelled() throws CloudbreakException {
Stack stack = TestUtil.stack();
Cluster cluster = TestUtil.cluster(TestUtil.blueprint(), stack, 1L);
stack.setCluster(cluster);
HostGroupAdjustmentJson hostGroupAdjustment = new HostGroupAdjustmentJson();
hostGroupAdjustment.setHostGroup("agent");
when(containerOrchestratorResolver.get(anyString())).thenReturn(new CancelledMockContainerOrchestrator());
when(stackRepository.findOneWithLists(anyLong())).thenReturn(stack);
when(tlsSecurityService.buildGatewayConfig(anyLong(), any(InstanceMetaData.class), anyInt(), any(), any())).thenReturn(new GatewayConfig("10.0.0.1", "198.0.0.1", "10.0.0.1", 8443, false));
when(clusterService.retrieveClusterByStackId(anyLong())).thenReturn(cluster);
when(hostGroupRepository.findHostGroupInClusterByName(anyLong(), anyString())).thenReturn(TestUtil.hostGroup());
Set<Container> containers = new HashSet<>();
Container ambariServer = new Container();
ambariServer.setName("server");
ambariServer.setImage(DockerContainer.AMBARI_SERVER.getName());
ambariServer.setHost("hostname-1");
ambariServer.setContainerId("1");
Container ambariAgent = new Container();
ambariAgent.setName("agent");
ambariAgent.setImage(DockerContainer.AMBARI_AGENT.getName());
ambariAgent.setHost("hostname-2");
ambariAgent.setContainerId("1");
containers.add(ambariAgent);
containers.add(ambariServer);
when(containerService.findContainersInCluster(anyLong())).thenReturn(containers);
underTest.addClusterContainers(stack.getId(), hostGroupAdjustment.getHostGroup(), hostGroupAdjustment.getScalingAdjustment());
}
Aggregations