use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses in project cloudbreak by hortonworks.
the class InstanceTerminationUnknownMock method addMockEndpoints.
public void addMockEndpoints() {
Service sparkService = getSparkService();
sparkService.get(SALT_BOOT_ROOT + "/health", (request, response) -> {
GenericResponse genericResponse = new GenericResponse();
genericResponse.setStatusCode(HttpStatus.OK.value());
return genericResponse;
}, gson()::toJson);
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<>();
JsonObject parsedRequest = new JsonParser().parse(request.body()).getAsJsonObject();
JsonArray nodeArray = parsedRequest.getAsJsonArray("clients");
for (int i = 0; i < nodeArray.size(); i++) {
String address = nodeArray.get(i).getAsString();
GenericResponse genericResponse = new GenericResponse();
genericResponse.setAddress(address);
genericResponse.setStatus(HostNameUtil.generateHostNameByIp(address));
genericResponse.setStatusCode(200);
responses.add(genericResponse);
}
genericResponses.setResponses(responses);
return genericResponses;
}, gson()::toJson);
sparkService.post(SALT_API_ROOT + "/run", new SaltApiRunPostResponse(getInstanceMap()));
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);
sparkService.get("/ws/v1/cluster/apps", (request, response) -> {
ObjectNode rootNode = JsonNodeFactory.instance.objectNode();
ArrayNode appNode = rootNode.putObject("apps").putArray("app");
appNode.addObject().put("amHostHttpAddress", "192.168.1.1");
return rootNode;
});
}
use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses in project cloudbreak by hortonworks.
the class MockSparkServer method addSaltMappings.
private static void addSaltMappings(Map<String, CloudVmMetaDataStatus> instanceMap) {
ObjectMapper objectMapper = new ObjectMapper();
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));
post(SALT_API_ROOT + "/run", new SaltApiRunPostResponse(instanceMap));
post(SALT_BOOT_ROOT + "/file", (request, response) -> {
response.status(HttpStatus.CREATED.value());
return response;
});
post(SALT_BOOT_ROOT + "/salt/server/pillar", (request, response) -> {
GenericResponse genericResponse = new GenericResponse();
genericResponse.setStatusCode(HttpStatus.OK.value());
return genericResponse;
}, GSON::toJson);
post(SALT_BOOT_ROOT + "/salt/action/distribute", (request, response) -> {
GenericResponses genericResponses = new GenericResponses();
genericResponses.setResponses(new ArrayList<>());
return genericResponses;
}, GSON::toJson);
post(SALT_BOOT_ROOT + "/hostname/distribute", (request, response) -> {
GenericResponses genericResponses = new GenericResponses();
List<GenericResponse> responses = new ArrayList<>();
for (Entry<String, CloudVmMetaDataStatus> stringCloudVmMetaDataStatusEntry : instanceMap.entrySet()) {
CloudVmMetaDataStatus cloudVmMetaDataStatus = stringCloudVmMetaDataStatusEntry.getValue();
GenericResponse genericResponse = new GenericResponse();
genericResponse.setAddress(cloudVmMetaDataStatus.getMetaData().getPrivateIp());
genericResponse.setStatus(HostNameUtil.generateHostNameByIp(cloudVmMetaDataStatus.getMetaData().getPrivateIp()));
genericResponse.setStatusCode(HttpStatus.OK.value());
responses.add(genericResponse);
}
genericResponses.setResponses(responses);
return genericResponses;
}, GSON::toJson);
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);
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.GenericResponses in project cloudbreak by hortonworks.
the class ScalingMock method addMockEndpoints.
public void addMockEndpoints() {
Service sparkService = getSparkService();
sparkService.get(SALT_BOOT_ROOT + "/health", (request, response) -> {
GenericResponse genericResponse = new GenericResponse();
genericResponse.setStatusCode(HttpStatus.OK.value());
return genericResponse;
}, gson()::toJson);
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<>();
JsonObject parsedRequest = new JsonParser().parse(request.body()).getAsJsonObject();
JsonArray nodeArray = parsedRequest.getAsJsonArray("clients");
for (int i = 0; i < nodeArray.size(); i++) {
String address = nodeArray.get(i).getAsString();
GenericResponse genericResponse = new GenericResponse();
genericResponse.setAddress(address);
genericResponse.setStatus(HostNameUtil.generateHostNameByIp(address));
genericResponse.setStatusCode(200);
responses.add(genericResponse);
}
genericResponses.setResponses(responses);
return genericResponses;
}, gson()::toJson);
sparkService.post(SALT_API_ROOT + "/run", new SaltApiRunPostResponse(getInstanceMap()));
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);
sparkService.get("/ws/v1/cluster/apps", (request, response) -> {
ObjectNode rootNode = JsonNodeFactory.instance.objectNode();
ArrayNode appNode = rootNode.putObject("apps").putArray("app");
appNode.addObject().put("amHostHttpAddress", "192.168.1.1");
return rootNode;
});
}
use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses in project cloudbreak by hortonworks.
the class SaltBootstrapTest method setUp.
@Before
public void setUp() {
saltConnector = mock(SaltConnector.class);
gatewayConfig = new GatewayConfig("1.1.1.1", "10.0.0.1", "172.16.252.43", "10-0-0-1.example.com", 9443, "serverCert", "clientCert", "clientKey", "saltpasswd", "saltbootpassword", "signkey", false, true, null, null);
GenericResponse response = new GenericResponse();
response.setStatusCode(HttpStatus.OK.value());
GenericResponses genericResponses = new GenericResponses();
genericResponses.setResponses(Collections.singletonList(response));
when(saltConnector.action(Mockito.any(SaltAction.class))).thenReturn(genericResponses);
when(saltConnector.run(Mockito.any(), Mockito.eq("network.default_route"), Mockito.any(), Mockito.any())).thenReturn(new DefaultRouteResponse(Collections.emptyList()));
NetworkInterfaceResponse networkInterfaceResponse = new NetworkInterfaceResponse();
List<Map<String, String>> networkResultList = new ArrayList<>();
networkMap = new HashMap<>();
networkMap.put("host-10-0-0-1.example.com", "10.0.0.1");
networkMap.put("host-10-0-0-2.example.com", "10.0.0.2");
networkMap.put("host-10-0-0-3.example.com", "10.0.0.3");
networkResultList.add(networkMap);
networkInterfaceResponse.setResult(networkResultList);
when(saltConnector.run(Mockito.any(), Mockito.eq("network.interface_ip"), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(networkInterfaceResponse);
}
use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses in project cloudbreak by hortonworks.
the class PillarSave method call.
@Override
public Boolean call() throws Exception {
LOGGER.info("Distribute pillar configs to: {}", targets);
if (!targets.isEmpty()) {
GenericResponses responses = sc.pillar(targets, pillar);
Set<String> failedTargets = new HashSet<>();
LOGGER.info("Salt pillar save responses: {}", responses);
for (GenericResponse genericResponse : responses.getResponses()) {
if (genericResponse.getStatusCode() != HttpStatus.OK.value()) {
LOGGER.info("Failed pillar save attempt to: " + genericResponse.getAddress());
String address = genericResponse.getAddress().split(":")[0];
failedTargets.addAll(originalTargets.stream().filter(a -> a.equals(address)).collect(Collectors.toList()));
}
}
targets = failedTargets;
if (!targets.isEmpty()) {
LOGGER.info("Missing nodes for pillar save: {}", targets);
throw new CloudbreakOrchestratorFailedException("There are missing nodes for pillar save: " + targets);
}
}
LOGGER.info("Pillar save has been completed on nodes: {}", originalTargets);
return true;
}
Aggregations