Search in sources :

Example 6 with GenericResponse

use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse in project cloudbreak by hortonworks.

the class SaltOrchestratorTest method isBootstrapApiAvailableFailTest.

@Test
public void isBootstrapApiAvailableFailTest() {
    SaltOrchestrator saltOrchestrator = new SaltOrchestrator();
    saltOrchestrator.init(parallelOrchestratorComponentRunner, exitCriteria);
    GenericResponse response = new GenericResponse();
    response.setStatusCode(404);
    when(saltConnector.health()).thenReturn(response);
    boolean bootstrapApiAvailable = saltOrchestrator.isBootstrapApiAvailable(gatewayConfig);
    assertFalse(bootstrapApiAvailable);
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with GenericResponse

use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse in project cloudbreak by hortonworks.

the class SaltOrchestratorTest method isBootstrapApiAvailableTest.

@Test
public void isBootstrapApiAvailableTest() {
    SaltOrchestrator saltOrchestrator = new SaltOrchestrator();
    saltOrchestrator.init(parallelOrchestratorComponentRunner, exitCriteria);
    GenericResponse response = new GenericResponse();
    response.setStatusCode(200);
    when(saltConnector.health()).thenReturn(response);
    boolean bootstrapApiAvailable = saltOrchestrator.isBootstrapApiAvailable(gatewayConfig);
    assertTrue(bootstrapApiAvailable);
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with GenericResponse

use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse in project cloudbreak by hortonworks.

the class SaltBootstrap method call.

@Override
public Boolean call() throws Exception {
    LOGGER.info("Bootstrapping of nodes [{}/{}]", originalTargets.size() - targets.size(), originalTargets.size());
    if (!targets.isEmpty()) {
        LOGGER.info("Missing targets for SaltBootstrap: {}", targets);
        SaltAction saltAction = createBootstrap();
        GenericResponses responses = sc.action(saltAction);
        Set<Node> failedTargets = new HashSet<>();
        LOGGER.info("SaltBootstrap responses: {}", responses);
        for (GenericResponse genericResponse : responses.getResponses()) {
            if (genericResponse.getStatusCode() != HttpStatus.OK.value()) {
                LOGGER.info("Failed to distributed salt run to: " + genericResponse.getAddress());
                String address = genericResponse.getAddress().split(":")[0];
                failedTargets.addAll(originalTargets.stream().filter(a -> a.getPrivateIp().equals(address)).collect(Collectors.toList()));
            }
        }
        targets = failedTargets;
        if (!targets.isEmpty()) {
            LOGGER.info("Missing nodes to run saltbootstrap: {}", targets);
            throw new CloudbreakOrchestratorFailedException("There are missing nodes from saltbootstrap: " + targets);
        }
    }
    String iFace = SaltStates.defaultRoute(sc, Glob.ALL).getGatewayInterfaceName();
    Map<String, String> networkResult = SaltStates.networkInterfaceIP(sc, Glob.ALL, iFace).getResultGroupByIP();
    originalTargets.forEach(node -> {
        if (!networkResult.containsKey(node.getPrivateIp())) {
            LOGGER.info("Salt-minion is not responding on host: {}, yet", node);
            targets.add(node);
        }
    });
    if (!targets.isEmpty()) {
        throw new CloudbreakOrchestratorFailedException("There are missing nodes from salt network response: " + targets);
    }
    LOGGER.info("Bootstrapping of nodes completed: {}", originalTargets.size());
    return true;
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) HashSet(java.util.HashSet)

Example 9 with GenericResponse

use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse in project cloudbreak by hortonworks.

the class SaltUpload method call.

@Override
public Boolean call() throws Exception {
    LOGGER.info("Uploading files to: {}", targets);
    if (!targets.isEmpty()) {
        LOGGER.info("Current targets for upload: {}", targets);
        GenericResponses responses = sc.upload(targets, path, fileName, content);
        Set<String> failedTargets = new HashSet<>();
        LOGGER.info("Salt file upload responses: {}", responses);
        for (GenericResponse genericResponse : responses.getResponses()) {
            if (genericResponse.getStatusCode() != HttpStatus.CREATED.value()) {
                LOGGER.info("Failed upload 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 file upload: {}", targets);
            throw new CloudbreakOrchestratorFailedException("There are missing nodes for file upload: " + targets);
        }
    }
    LOGGER.info("File upload has been completed on nodes: {}", originalTargets);
    return true;
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) HashSet(java.util.HashSet)

Example 10 with GenericResponse

use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse in project cloudbreak by hortonworks.

the class MockClusterCreationWithSaltFailTest method addSaltMappings.

private void addSaltMappings(Map<String, CloudVmMetaDataStatus> instanceMap) {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setVisibility(objectMapper.getVisibilityChecker().withGetterVisibility(Visibility.NONE));
    post(SALT_API_ROOT + "/run", new SaltApiRunPostResponse(instanceMap) {

        @Override
        protected Object jobsLookupJid() {
            return responseFromJsonFile("saltapi/lookup_jid_fail_response.json");
        }
    });
    post(SALT_BOOT_ROOT + "/salt/server/pillar", (request, response) -> {
        GenericResponse genericResponse = new GenericResponse();
        genericResponse.setStatusCode(HttpStatus.OK.value());
        return genericResponse;
    }, gson()::toJson);
}
Also used : SaltApiRunPostResponse(com.sequenceiq.it.spark.salt.SaltApiRunPostResponse) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

GenericResponse (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse)19 GenericResponses (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses)14 SaltApiRunPostResponse (com.sequenceiq.it.spark.salt.SaltApiRunPostResponse)8 ArrayList (java.util.ArrayList)8 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 JsonArray (com.google.gson.JsonArray)5 JsonObject (com.google.gson.JsonObject)5 JsonParser (com.google.gson.JsonParser)5 Service (spark.Service)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)4 HashSet (java.util.HashSet)4 SaltAction (com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction)3 Map (java.util.Map)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)2 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)2 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)2