Search in sources :

Example 1 with FingerprintsResponse

use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse in project cloudbreak by hortonworks.

the class FingerprintFromSbCollector method collectFingerprintFromMinions.

public FingerprintsResponse collectFingerprintFromMinions(SaltConnector sc, List<Minion> minionsToAccept) throws CloudbreakOrchestratorFailedException {
    FingerprintsResponse fingerprintsResponse;
    try {
        fingerprintsResponse = sc.collectFingerPrints(new FingerprintRequest(minionsToAccept));
    } catch (Exception e) {
        LOGGER.error("Couldn't collect fingerprints for minions: {}", minionsToAccept, e);
        throw new CloudbreakOrchestratorFailedException("Couldn't collect fingerprints for minions", e);
    }
    validateFingerprintResponse(minionsToAccept, fingerprintsResponse);
    return fingerprintsResponse;
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) FingerprintRequest(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintRequest) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)

Example 2 with FingerprintsResponse

use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse in project cloudbreak by hortonworks.

the class MinionAcceptorTest method testAllMinionsAcceptedWithMatchingFingerprint.

@Test
public void testAllMinionsAcceptedWithMatchingFingerprint() throws CloudbreakOrchestratorFailedException {
    MinionKeysOnMasterResponse keysOnMasterResponse = mock(MinionKeysOnMasterResponse.class);
    MinionFingersOnMasterResponse fingersOnMasterResponse = mock(MinionFingersOnMasterResponse.class);
    FingerprintFromSbCollector fingerprintCollector = mock(FingerprintFromSbCollector.class);
    FingerprintsResponse fingerprintsResponse = mock(FingerprintsResponse.class);
    Minion m1 = new Minion();
    m1.setHostName("m1");
    m1.setDomain("d");
    m1.setAddress("1.1.1.1");
    Minion m2 = new Minion();
    m2.setHostName("m2");
    m2.setDomain("d");
    m2.setAddress("1.1.1.2");
    Minion m3 = new Minion();
    m3.setHostName("m3");
    m3.setDomain("d");
    m3.setAddress("1.1.1.3");
    Minion m4 = new Minion();
    m4.setHostName("m4");
    m4.setDomain("d");
    m4.setAddress("1.1.1.4");
    Fingerprint fp1 = new Fingerprint();
    fp1.setFingerprint("finger1");
    fp1.setAddress("1.1.1.1");
    Fingerprint fp2 = new Fingerprint();
    fp2.setFingerprint("finger2");
    fp2.setAddress("1.1.1.2");
    Fingerprint fp3 = new Fingerprint();
    fp3.setFingerprint("badFinger");
    fp3.setAddress("1.1.1.3");
    when(keysOnMasterResponse.getAllMinions()).thenReturn(List.of("m2.d", "m1.d", "m3.d", "m4.d"));
    when(keysOnMasterResponse.getUnacceptedMinions()).thenReturn(List.of("m2.d", "m1.d", "m3.d"));
    when(fingersOnMasterResponse.getUnacceptedMinions()).thenReturn(Map.of("m1.d", "finger1", "m2.d", "finger2", "m3.d", "finger3"));
    when(sc.wheel(eq("key.list_all"), isNull(), eq(MinionKeysOnMasterResponse.class))).thenReturn(keysOnMasterResponse);
    when(sc.wheel(eq("key.finger"), anyCollection(), eq(MinionFingersOnMasterResponse.class))).thenReturn(fingersOnMasterResponse);
    when(fingerprintCollector.collectFingerprintFromMinions(eq(sc), argThat(arg -> arg.containsAll(List.of(m1, m2, m3))))).thenReturn(fingerprintsResponse);
    when(fingerprintsResponse.getFingerprints()).thenReturn(List.of(fp2, fp1, fp3));
    MinionAcceptor underTest = spy(new MinionAcceptor(List.of(sc), List.of(m1, m2, m3, m4), new EqualMinionFpMatcher(), fingerprintCollector));
    underTest.acceptMinions();
    verify(sc).wheel(eq("key.accept"), argThat(arg -> arg.containsAll(List.of("m2.d", "m1.d"))), eq(Object.class));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) Fingerprint(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Fingerprint) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) PowerMockito.when(org.powermock.api.mockito.PowerMockito.when) Mockito.spy(org.mockito.Mockito.spy) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) Mockito.never(org.mockito.Mockito.never) List(java.util.List) MinionKeysOnMasterResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionKeysOnMasterResponse) Minion(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Minion) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) Map(java.util.Map) MinionFingersOnMasterResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionFingersOnMasterResponse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) Mockito.mock(org.mockito.Mockito.mock) Fingerprint(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Fingerprint) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) MinionFingersOnMasterResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionFingersOnMasterResponse) Minion(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Minion) MinionKeysOnMasterResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionKeysOnMasterResponse) Test(org.junit.jupiter.api.Test)

Example 3 with FingerprintsResponse

use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse in project cloudbreak by hortonworks.

the class FingerprintFromSbCollectorTest method testHttpStatusValidation.

@Test
public void testHttpStatusValidation() {
    FingerprintsResponse response = new FingerprintsResponse();
    response.setStatusCode(HttpStatus.SERVICE_UNAVAILABLE.value());
    when(sc.collectFingerPrints(any(FingerprintRequest.class))).thenReturn(response);
    assertThrows(CloudbreakOrchestratorFailedException.class, () -> underTest.collectFingerprintFromMinions(sc, List.of()));
}
Also used : FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) FingerprintRequest(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintRequest) Test(org.junit.jupiter.api.Test)

Example 4 with FingerprintsResponse

use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse in project cloudbreak by hortonworks.

the class FingerprintFromSbCollectorTest method testSuccessfulCollection.

@Test
public void testSuccessfulCollection() throws CloudbreakOrchestratorFailedException {
    FingerprintsResponse response = new FingerprintsResponse();
    response.setStatusCode(HttpStatus.OK.value());
    Fingerprint fp = new Fingerprint();
    fp.setAddress("1.1.1.1");
    fp.setFingerprint("asdf");
    Fingerprint fp2 = new Fingerprint();
    fp2.setAddress("1.1.1.2");
    fp2.setFingerprint("gfsd");
    response.setFingerprints(List.of(fp, fp2));
    when(sc.collectFingerPrints(any(FingerprintRequest.class))).thenReturn(response);
    Minion m1 = new Minion();
    m1.setAddress("1.1.1.1");
    m1.setHostName("m1");
    m1.setDomain("domain");
    Minion m2 = new Minion();
    m2.setAddress("1.1.1.2");
    m2.setHostName("m2");
    m2.setDomain("domain");
    FingerprintsResponse result = underTest.collectFingerprintFromMinions(sc, List.of(m1, m2));
    assertEquals(response, result);
}
Also used : Fingerprint(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Fingerprint) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) Minion(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Minion) FingerprintRequest(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintRequest) Test(org.junit.jupiter.api.Test)

Example 5 with FingerprintsResponse

use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse in project cloudbreak by hortonworks.

the class FingerprintFromSbCollectorTest method testAllMinionsCollectedValidation.

@Test
public void testAllMinionsCollectedValidation() {
    FingerprintsResponse response = new FingerprintsResponse();
    response.setStatusCode(HttpStatus.OK.value());
    Fingerprint fp = new Fingerprint();
    fp.setAddress("1.1.1.1");
    response.setFingerprints(List.of(fp));
    when(sc.collectFingerPrints(any(FingerprintRequest.class))).thenReturn(response);
    Minion m1 = new Minion();
    m1.setAddress("1.1.1.1");
    m1.setHostName("m1");
    m1.setDomain("domain");
    Minion m2 = new Minion();
    m2.setAddress("1.1.1.2");
    m2.setHostName("m2");
    m2.setDomain("domain");
    assertThrows(CloudbreakOrchestratorFailedException.class, () -> underTest.collectFingerprintFromMinions(sc, List.of(m1, m2)));
}
Also used : Fingerprint(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Fingerprint) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) Minion(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Minion) FingerprintRequest(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintRequest) Test(org.junit.jupiter.api.Test)

Aggregations

FingerprintsResponse (com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse)6 Fingerprint (com.sequenceiq.cloudbreak.orchestrator.salt.domain.Fingerprint)4 FingerprintRequest (com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintRequest)4 Minion (com.sequenceiq.cloudbreak.orchestrator.salt.domain.Minion)4 Test (org.junit.jupiter.api.Test)4 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)3 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)2 MinionFingersOnMasterResponse (com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionFingersOnMasterResponse)2 MinionKeysOnMasterResponse (com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionKeysOnMasterResponse)2 List (java.util.List)2 Map (java.util.Map)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Set (java.util.Set)1 Predicate.not (java.util.function.Predicate.not)1 Collectors (java.util.stream.Collectors)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.anyCollection (org.mockito.ArgumentMatchers.anyCollection)1