use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse in project cloudbreak by hortonworks.
the class StackCreationMock method addSaltMappings.
public void addSaltMappings() {
Map<String, CloudVmMetaDataStatus> instanceMap = getInstanceMap();
ObjectMapper objectMapper = new ObjectMapper();
Service sparkService = getSparkService();
sparkService.get(SALT_BOOT_ROOT + "/health", (request, response) -> {
GenericResponse genericResponse = new GenericResponse();
genericResponse.setStatusCode(HttpStatus.OK.value());
return genericResponse;
}, gson()::toJson);
objectMapper.setVisibility(objectMapper.getVisibilityChecker().withGetterVisibility(Visibility.NONE));
sparkService.post(SALT_API_ROOT + "/run", new SaltApiRunPostResponse(instanceMap));
sparkService.post(SALT_BOOT_ROOT + "/file", (request, response) -> {
response.status(HttpStatus.CREATED.value());
return response;
});
sparkService.post(SALT_BOOT_ROOT + "/salt/server/pillar", (request, response) -> {
GenericResponse genericResponse = new GenericResponse();
genericResponse.setStatusCode(HttpStatus.OK.value());
return genericResponse;
}, gson()::toJson);
sparkService.post(SALT_BOOT_ROOT + "/salt/action/distribute", (request, response) -> {
GenericResponses genericResponses = new GenericResponses();
genericResponses.setResponses(new ArrayList<>());
return genericResponses;
}, gson()::toJson);
sparkService.post(SALT_BOOT_ROOT + "/hostname/distribute", (request, response) -> {
GenericResponses genericResponses = new GenericResponses();
List<GenericResponse> responses = new ArrayList<>();
for (CloudVmMetaDataStatus status : instanceMap.values()) {
GenericResponse genericResponse = new GenericResponse();
genericResponse.setAddress(status.getMetaData().getPrivateIp());
genericResponse.setStatus(HostNameUtil.generateHostNameByIp(status.getMetaData().getPrivateIp()));
genericResponse.setStatusCode(HttpStatus.OK.value());
responses.add(genericResponse);
}
genericResponses.setResponses(responses);
return genericResponses;
}, gson()::toJson);
sparkService.post(SALT_BOOT_ROOT + "/file/distribute", (request, response) -> {
GenericResponses genericResponses = new GenericResponses();
GenericResponse genericResponse = new GenericResponse();
genericResponse.setStatusCode(HttpStatus.CREATED.value());
genericResponses.setResponses(Collections.singletonList(genericResponse));
return genericResponses;
}, gson()::toJson);
sparkService.post(SALT_BOOT_ROOT + "/salt/server/pillar/distribute", (request, response) -> {
GenericResponses genericResponses = new GenericResponses();
GenericResponse genericResponse = new GenericResponse();
genericResponse.setStatusCode(HttpStatus.OK.value());
genericResponses.setResponses(Collections.singletonList(genericResponse));
return genericResponses;
}, gson()::toJson);
}
use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse in project cloudbreak by hortonworks.
the class SaltConnector method health.
public GenericResponse health() {
Response response = saltTarget.path(SaltEndpoint.BOOT_HEALTH.getContextPath()).request().get();
GenericResponse responseEntity = JaxRSUtil.response(response, GenericResponse.class);
LOGGER.info("SaltBoot. Health response: {}", responseEntity);
return responseEntity;
}
use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse in project cloudbreak by hortonworks.
the class SaltConnector method members.
public Map<String, String> members(List<String> privateIps) throws CloudbreakOrchestratorFailedException {
Map<String, List<String>> clients = singletonMap("clients", privateIps);
Response response = saltTarget.path(BOOT_HOSTNAME_ENDPOINT.getContextPath()).request().header(SIGN_HEADER, PkiUtil.generateSignature(signatureKey, toJson(clients).getBytes())).post(Entity.json(clients));
GenericResponses responses = JaxRSUtil.response(response, GenericResponses.class);
List<GenericResponse> failedResponses = responses.getResponses().stream().filter(genericResponse -> !ACCEPTED_STATUSES.contains(genericResponse.getStatusCode())).collect(Collectors.toList());
if (!failedResponses.isEmpty()) {
failedResponseErrorLog(failedResponses);
String failedNodeAddresses = failedResponses.stream().map(GenericResponse::getAddress).collect(Collectors.joining(","));
throw new CloudbreakOrchestratorFailedException("Hostname resolution failed for nodes: " + failedNodeAddresses);
}
return responses.getResponses().stream().collect(Collectors.toMap(GenericResponse::getAddress, GenericResponse::getStatus));
}
use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse in project cloudbreak by hortonworks.
the class SaltConnector method pillar.
public GenericResponses pillar(Iterable<String> targets, Pillar pillar) {
Response distributeResponse = saltTarget.path(SaltEndpoint.BOOT_PILLAR_DISTRIBUTE.getContextPath()).request().header(SIGN_HEADER, PkiUtil.generateSignature(signatureKey, toJson(pillar).getBytes())).post(Entity.json(pillar));
if (distributeResponse.getStatus() == HttpStatus.SC_NOT_FOUND) {
// simple pillar save for CB <= 1.14
distributeResponse.close();
Response singleResponse = saltTarget.path(SaltEndpoint.BOOT_PILLAR_SAVE.getContextPath()).request().header(SIGN_HEADER, PkiUtil.generateSignature(signatureKey, toJson(pillar).getBytes())).post(Entity.json(pillar));
GenericResponses genericResponses = new GenericResponses();
GenericResponse genericResponse = new GenericResponse();
genericResponse.setAddress(targets.iterator().next());
genericResponse.setStatusCode(singleResponse.getStatus());
genericResponses.setResponses(Collections.singletonList(genericResponse));
singleResponse.close();
return genericResponses;
}
return JaxRSUtil.response(distributeResponse, GenericResponses.class);
}
use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse in project cloudbreak by hortonworks.
the class PillarSaveTest method testDiscovery.
@Test
public void testDiscovery() throws Exception {
SaltConnector saltConnector = mock(SaltConnector.class);
GenericResponses responses = new GenericResponses();
GenericResponse response = new GenericResponse();
response.setStatusCode(HttpStatus.OK.value());
response.setAddress("10.0.0.2");
responses.setResponses(Collections.singletonList(response));
when(saltConnector.pillar(any(), any(Pillar.class))).thenReturn(responses);
Set<Node> nodes = new HashSet<>();
nodes.add(new Node("10.0.0.1", "1.1.1.1", "10-0-0-1.example.com", "hg"));
nodes.add(new Node("10.0.0.2", "1.1.1.2", "10-0-0-2.example.com", "hg"));
nodes.add(new Node("10.0.0.3", "1.1.1.3", "10-0-0-3.example.com", "hg"));
PillarSave pillarSave = new PillarSave(saltConnector, Sets.newHashSet("10.0.0.1"), nodes);
pillarSave.call();
ArgumentCaptor<Pillar> pillarCaptor = ArgumentCaptor.forClass(Pillar.class);
ArgumentCaptor<Set> targetCaptor = ArgumentCaptor.forClass(Set.class);
verify(saltConnector).pillar(targetCaptor.capture(), pillarCaptor.capture());
Pillar pillar = pillarCaptor.getValue();
Map<String, Map<String, Map<String, Object>>> pillarJson = (Map<String, Map<String, Map<String, Object>>>) pillar.getJson();
Map<String, Map<String, Object>> hostMap = pillarJson.entrySet().iterator().next().getValue();
for (Node node : nodes) {
Assert.assertEquals(node.getHostname(), hostMap.get(node.getPrivateIp()).get("fqdn"));
Assert.assertEquals(node.getHostname().split("\\.")[0], hostMap.get(node.getPrivateIp()).get("hostname"));
Assert.assertEquals(Boolean.TRUE, hostMap.get(node.getPrivateIp()).get("public_address"));
}
}
Aggregations