org.springframework.data.util.Pair Java Examples

The following examples show how to use org.springframework.data.util.Pair. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HostDeletionServiceTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void successfulRemoveServersIfAllHostReturned() throws FreeIpaClientException {
    Set<String> hosts = Set.of("host1", "host2");
    IpaServer ipaServer1 = new IpaServer();
    ipaServer1.setCn("host1");
    IpaServer ipaServer2 = new IpaServer();
    ipaServer2.setCn("host2");
    when(freeIpaClient.findAllServers()).thenReturn(Set.of(ipaServer1, ipaServer2));

    Pair<Set<String>, Map<String, String>> result = underTest.removeServers(freeIpaClient, hosts);

    assertTrue(result.getSecond().isEmpty());
    assertEquals(2, result.getFirst().size());
    assertTrue(result.getFirst().contains(ipaServer1.getCn()));
    assertTrue(result.getFirst().contains(ipaServer2.getCn()));
    verify(freeIpaClient).deleteServer(eq("host1"));
    verify(freeIpaClient).deleteServer(eq("host2"));
}
 
Example #2
Source File: GetCriticalFilesAdapter.java    From coderadar with MIT License 6 votes vote down vote up
@Override
public List<FileAndCommitsForTimePeriod> getFrequentlyChangedFiles(
    long projectId,
    String commitHash,
    Date startDate,
    int frequency,
    List<FilePattern> filePatterns) {
  Pair<List<String>, List<String>> includesAndExcludes =
      PatternUtil.mapPatternsToRegex(filePatterns);
  return mapFileAndCommitsForTimePeriodResult(
      fileRepository.getFrequentlyChangedFiles(
          projectId,
          commitHash,
          startDate.getTime(),
          frequency,
          includesAndExcludes.getFirst(),
          includesAndExcludes.getSecond()));
}
 
Example #3
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void testRevokeCertsWhenNoCmHostnameProvided() throws FreeIpaClientException {
    Set<String> hosts = Set.of(
            "test-wl-1-worker0.env.xyz.wl.cloudera.site",
            "test-wl-1-worker1.env.xyz.wl.cloudera.site",
            "test-wl-1-master2111111111.env.xyz.wl.cloudera.site",
            "test-wl-1-compute3.env.xyz.wl.cloudera.site"
    );
    Set<Cert> certs = Set.of(
            createCert("CN=test-wl-2-master2", 1, false),
            createCert("CN=test-wl-1-master2", 2, false),
            createCert("CN=test-wl-3-master1", 3, true),
            createCert("CN=test-datalake-1-master1", 4, false),
            createCert("CN=ipaserver0.env.xyz.wl.cloudera.site,O=ENV.XYZ.WL.CLOUDERA.SITE", 50, false)
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClient.findAllCert()).thenReturn(certs);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);

    Pair<Set<String>, Map<String, String>> result = cleanupService.revokeCerts(STACK_ID, hosts);

    verifyRevokeNotInvoked(freeIpaClient, 1, 2, 3, 4, 50);
    assertEquals(0, result.getFirst().size());
    assertEquals(0, result.getSecond().size());
}
 
Example #4
Source File: CleanupService.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
public Pair<Set<String>, Map<String, String>> revokeCerts(Long stackId, Set<String> hosts) throws FreeIpaClientException {
    FreeIpaClient client = getFreeIpaClient(stackId);
    Set<String> certCleanupSuccess = new HashSet<>();
    Map<String, String> certCleanupFailed = new HashMap<>();
    Set<Cert> certs = client.findAllCert();
    certs.stream()
            .filter(cert -> hosts.stream().anyMatch(host -> substringBefore(host, ".").equals(substringBefore(removeStart(cert.getSubject(), "CN="), "."))))
            .filter(cert -> !cert.isRevoked())
            .forEach(cert -> {
                try {
                    client.revokeCert(cert.getSerialNumber());
                    certCleanupSuccess.add(cert.getSubject());
                } catch (FreeIpaClientException e) {
                    LOGGER.error("Couldn't revoke certificate: {}", cert, e);
                    certCleanupFailed.put(cert.getSubject(), e.getMessage());
                }
            });
    return Pair.of(certCleanupSuccess, certCleanupFailed);
}
 
Example #5
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void testRevokeCertsWithAlreadyRevokedCert() throws FreeIpaClientException {
    Set<String> hosts = Set.of(
            "test-wl-1-worker0.env.xyz.wl.cloudera.site",
            "test-wl-1-worker1.env.xyz.wl.cloudera.site",
            "test-wl-1-master2.env.xyz.wl.cloudera.site",
            "test-wl-1-compute3.env.xyz.wl.cloudera.site"
    );
    Set<Cert> certs = Set.of(
            createCert("CN=test-wl-2-master2", 1, false),
            createCert("CN=test-wl-1-master2", 2, true),
            createCert("CN=test-wl-3-master1", 3, true),
            createCert("CN=test-datalake-1-master1", 4, false),
            createCert("CN=ipaserver0.env.xyz.wl.cloudera.site,O=ENV.XYZ.WL.CLOUDERA.SITE", 50, false)
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClient.findAllCert()).thenReturn(certs);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);

    Pair<Set<String>, Map<String, String>> result = cleanupService.revokeCerts(STACK_ID, hosts);

    verifyRevokeNotInvoked(freeIpaClient, 1, 2, 3, 4, 50);
    assertEquals(0, result.getFirst().size());
    assertEquals(0, result.getSecond().size());
}
 
Example #6
Source File: CleanupService.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
public Pair<Set<String>, Map<String, String>> removeRoles(Long stackId, Set<String> roles) throws FreeIpaClientException {
    FreeIpaClient client = getFreeIpaClient(stackId);
    Set<String> roleCleanupSuccess = new HashSet<>();
    Map<String, String> roleCleanupFailed = new HashMap<>();
    Set<String> roleNames = client.findAllRole().stream().map(Role::getCn).collect(Collectors.toSet());
    roles.stream().filter(roleNames::contains).forEach(role -> {
        try {
            LOGGER.debug("Delete role: {}", role);
            client.deleteRole(role);
            roleCleanupSuccess.add(role);
        } catch (FreeIpaClientException e) {
            if (FreeIpaClientExceptionUtil.isNotFoundException(e)) {
                roleCleanupSuccess.add(role);
            } else {
                LOGGER.info("Role delete failed for role: {}", role, e);
                roleCleanupFailed.put(role, e.getMessage());
            }
        }
    });
    return Pair.of(roleCleanupSuccess, roleCleanupFailed);
}
 
Example #7
Source File: CleanupService.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
public Pair<Set<String>, Map<String, String>> removeVaultEntries(Long stackId, Set<String> hosts) throws FreeIpaClientException {
    Set<String> vaultCleanupSuccess = new HashSet<>();
    Map<String, String> vaultCleanupFailed = new HashMap<>();
    Stack stack = stackService.getStackById(stackId);
    FreeIpaClient freeIpaClient = getFreeIpaClient(stackId);
    for (String host : hosts) {
        try {
            HostRequest hostRequest = new HostRequest();
            hostRequest.setEnvironmentCrn(stack.getEnvironmentCrn());
            hostRequest.setServerHostName(host);
            kerberosMgmtV1Service.removeHostRelatedKerberosConfiguration(hostRequest, stack.getAccountId(), freeIpaClient);
            vaultCleanupSuccess.add(host);
        } catch (DeleteException | FreeIpaClientException e) {
            LOGGER.info("Vault secret cleanup failed for host: {}", host, e);
            vaultCleanupFailed.put(host, e.getMessage());
        }
    }
    return Pair.of(vaultCleanupSuccess, vaultCleanupFailed);
}
 
Example #8
Source File: PathUtils.java    From syndesis with Apache License 2.0 6 votes vote down vote up
/**
 * Simple method parses the input path and returns a set of string {@link Properties}
 * @return properties object
 */
public static List<Pair<String, String>> getOptions(String path) {
    StringTokenizer tokenizer = new StringTokenizer(path, OPTION_SEPARATOR);

    List<Pair<String, String>> props = new ArrayList<>();

    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();

        // Now we split this token via the "="
        StringTokenizer strTkzr = new StringTokenizer(token, VALUE_SEPARATOR);
        String key = strTkzr.nextToken();
        String value = strTkzr.nextToken();
        try {
            props.add(Pair.of(URLDecoder.decode(key, "UTF-8") , URLDecoder.decode(value, "UTF-8")));
        } catch (UnsupportedEncodingException e) {
            throw new UncheckedIOException(e);
        }
    }

    return props;

}
 
Example #9
Source File: PageableDataProvider.java    From spring-data-provider with Apache License 2.0 6 votes vote down vote up
public static Pair<Integer, Integer> limitAndOffsetToPageSizeAndNumber(
        int offset, int limit) {
    int minPageSize = limit;
    int lastIndex = offset + limit - 1;
    int maxPageSize = lastIndex + 1;

    for (double pageSize = minPageSize; pageSize <= maxPageSize; pageSize++) {
        int startPage = (int) (offset / pageSize);
        int endPage = (int) (lastIndex / pageSize);
        if (startPage == endPage) {
            // It fits on one page, let's go with that
            return Pair.of((int) pageSize, startPage);
        }
    }

    // Should not really get here
    return Pair.of(maxPageSize, 0);
}
 
Example #10
Source File: HostDeletionServiceTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void successfulDeletionIfAllHostReturned() throws FreeIpaClientException {
    Set<String> hosts = Set.of("host1", "host2");
    Host host1 = new Host();
    host1.setFqdn("host1");
    Host host2 = new Host();
    host2.setFqdn("host2");
    when(freeIpaClient.findAllHost()).thenReturn(Set.of(host1, host2));

    Pair<Set<String>, Map<String, String>> result = underTest.removeHosts(freeIpaClient, hosts);

    assertTrue(result.getSecond().isEmpty());
    assertEquals(2, result.getFirst().size());
    assertTrue(result.getFirst().contains(host1.getFqdn()));
    assertTrue(result.getFirst().contains(host2.getFqdn()));
    verify(freeIpaClient).deleteHost(eq("host1"));
    verify(freeIpaClient).deleteHost(eq("host2"));
}
 
Example #11
Source File: HostDeletionServiceTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void testOneFailedDeletion() throws FreeIpaClientException {
    Set<String> hosts = Set.of("host1", "host2");
    Host host1 = new Host();
    host1.setFqdn("host1");
    Host host2 = new Host();
    host2.setFqdn("host2");
    when(freeIpaClient.findAllHost()).thenReturn(Set.of(host1, host2));
    when(freeIpaClient.deleteHost(host2.getFqdn())).thenThrow(new FreeIpaClientException("not handled"));

    Pair<Set<String>, Map<String, String>> result = underTest.removeHosts(freeIpaClient, hosts);

    assertEquals(1, result.getFirst().size());
    assertEquals(1, result.getSecond().size());
    assertTrue(result.getFirst().contains(host1.getFqdn()));
    assertTrue(result.getSecond().keySet().contains(host2.getFqdn()));
    assertTrue(result.getSecond().values().contains("not handled"));
}
 
Example #12
Source File: BrokerStomp.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
private void clearSession(WebSocketSession session) {
    log.info("cleanup session: {}", session.getId());

    if (!sessionContext.containsKey(session.getId())) {
        log.error("not exist session: {}, skip it", session.getId());
        return;
    }

    // remove session id and subscriptions
    Map<String, Pair<String, String>> subscriptions = sessionContext.get(session.getId());
    sessionContext.remove(session.getId());

    log.info("find subscriptions: {}, try to IConsumer.unSubscribe one by one", subscriptions.size());
    for (Map.Entry<String, Pair<String, String>> subscription : subscriptions.entrySet()) {
        try {
            boolean result = this.iconsumer.unSubscribe(subscription.getValue().getFirst());
            log.info("IConsumer.unSubscribe result, {} <-> {}", subscription, result);
        } catch (BrokerException e) {
            log.error("exception in IConsumer.unSubscribe", e);
        }
    }
}
 
Example #13
Source File: WebSocketTransport.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
public String stompSubscribe(TopicContent topic, IWeEventClient.EventListener listener) throws BrokerException {
    WeEventStompCommand stompCommand = new WeEventStompCommand();
    Long asyncSeq = this.sequence.incrementAndGet();
    String req = stompCommand.encodeSubscribe(topic, asyncSeq);
    this.sequence2Id.put(Long.toString(asyncSeq), asyncSeq);

    StompHeaderAccessor stompHeaderAccessor = getStompHeaderAccessor(stompCommand, req, asyncSeq, "subscribe");

    // cache the subscription id and the WeEventTopic,the subscription2EventCache which can use for reconnect
    String subscriptionId = stompHeaderAccessor.getFirstNativeHeader("subscription-id");
    topic.getExtension().put(WeEvent.WeEvent_SubscriptionId, subscriptionId);

    this.subscription2EventCache.put(subscriptionId, Pair.of(topic, listener));
    // map the receipt id and the subscription id
    this.receiptId2SubscriptionId.put(String.valueOf(asyncSeq), subscriptionId);
    this.subscriptionId2ReceiptId.put(subscriptionId, String.valueOf(asyncSeq));
    log.info("subscribe success, topic: {}", topic.getTopicName());

    return subscriptionId;

}
 
Example #14
Source File: WebSocketTransport.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
public void stompConnect(String userName, String password) throws BrokerException {
    WeEventStompCommand stompCommand = new WeEventStompCommand();
    String req = stompCommand.encodeConnect(userName, password);

    this.sequence2Id.put(Long.toString(0L), 0L);
    getStompHeaderAccessor(stompCommand, req, 0L, "stompConnect");
    log.info("stomp connect success.");

    this.account = Pair.of(userName, password);

    // initialize connection context
    this.cleanup();
    this.receiptId2SubscriptionId.clear();
    this.subscriptionId2ReceiptId.clear();
    this.connected = true;
}
 
Example #15
Source File: HostDeletionServiceTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void testOneAlreadyDeleted() throws FreeIpaClientException {
    Set<String> hosts = Set.of("host1", "host2");
    Host host1 = new Host();
    host1.setFqdn("host1");
    Host host2 = new Host();
    host2.setFqdn("host2");
    when(freeIpaClient.findAllHost()).thenReturn(Set.of(host1, host2));
    String message = "already deleted";
    when(freeIpaClient.deleteHost(host2.getFqdn())).thenThrow(new FreeIpaClientException(message, new JsonRpcClientException(NOT_FOUND, message, null)));

    Pair<Set<String>, Map<String, String>> result = underTest.removeHosts(freeIpaClient, hosts);

    assertEquals(2, result.getFirst().size());
    assertEquals(0, result.getSecond().size());
    assertTrue(result.getFirst().contains(host1.getFqdn()));
    assertTrue(result.getFirst().contains(host2.getFqdn()));
}
 
Example #16
Source File: RqueueUtilityServiceImpl.java    From rqueue with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Pair<String, String> getLatestVersion() {
  if (System.currentTimeMillis() - versionFetchTime > Constants.MILLIS_IN_A_DAY) {
    Map<String, Object> response =
        readUrl(Constants.GITHUB_API_FOR_LATEST_RELEASE, LinkedHashMap.class);
    if (response != null) {
      String tagName = (String) response.get("tag_name");
      if (tagName != null && !tagName.isEmpty()) {
        if (Character.toLowerCase(tagName.charAt(0)) == 'v') {
          releaseLink = (String) response.get("html_url");
          latestVersion = tagName.substring(1);
          versionFetchTime = System.currentTimeMillis();
        }
      }
    }
  }
  return Pair.of(releaseLink, latestVersion);
}
 
Example #17
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testRevokeCertsWithLongHostnames() throws FreeIpaClientException {
    Set<String> hosts = Set.of(
            "test-wl-1-worker0.env.xyz.wl.cloudera.site",
            "test-wl-1-worker1.env.xyz.wl.cloudera.site",
            "test-wl-1-master2.env.xyz.wl.cloudera.site",
            "test-wl-1-compute3.env.xyz.wl.cloudera.site"
    );
    Set<Cert> certs = Set.of(
            createCert("CN=test-wl-2-master2", 1, false),
            createCert("CN=test-wl-1-master2", 2, false),
            createCert("CN=test-wl-3-master1", 3, true),
            createCert("CN=test-datalake-1-master1", 4, false),
            createCert("CN=ipaserver0.env.xyz.wl.cloudera.site,O=ENV.XYZ.WL.CLOUDERA.SITE", 50, false)
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClient.findAllCert()).thenReturn(certs);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);

    Pair<Set<String>, Map<String, String>> result = cleanupService.revokeCerts(STACK_ID, hosts);

    verify(freeIpaClient, times(1)).revokeCert(2);
    verifyRevokeNotInvoked(freeIpaClient, 1, 3, 4, 50);
    assertEquals(1, result.getFirst().size());
    assertEquals(0, result.getSecond().size());
    assertTrue(result.getFirst().stream().allMatch("CN=test-wl-1-master2"::equals));
}
 
Example #18
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testRevokeCertsWithShortHostnames() throws FreeIpaClientException {
    Set<String> hosts = Set.of(
            "test-wl-1-worker0",
            "test-wl-1-worker1",
            "test-wl-1-master2",
            "test-wl-1-compute3"
    );
    Set<Cert> certs = Set.of(
            createCert("CN=test-wl-2-master2", 1, false),
            createCert("CN=test-wl-1-master2", 2, false),
            createCert("CN=test-wl-3-master1", 3, false),
            createCert("CN=test-datalake-1-master1", 4, false),
            createCert("CN=ipaserver0.env.xyz.wl.cloudera.site,O=ENV.XYZ.WL.CLOUDERA.SITE", 50, false)
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClient.findAllCert()).thenReturn(certs);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);

    Pair<Set<String>, Map<String, String>> result = cleanupService.revokeCerts(STACK_ID, hosts);

    verify(freeIpaClient, times(1)).revokeCert(2);
    verifyRevokeNotInvoked(freeIpaClient, 1, 3, 4, 50);
    assertEquals(1, result.getFirst().size());
    assertEquals(0, result.getSecond().size());
    assertTrue(result.getFirst().stream().allMatch("CN=test-wl-1-master2"::equals));
}
 
Example #19
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testRevokeCertsWithMixedHostnames() throws FreeIpaClientException {
    Set<String> hosts = Set.of(
            "test-wl-1-worker0.env.xyz.wl.cloudera.site",
            "test-wl-1-worker1",
            "test-wl-1-master2",
            "test-wl-1-compute3.env.xyz.wl.cloudera.site"
    );
    Set<Cert> certs = Set.of(
            createCert("CN=test-wl-2-master2", 1, false),
            createCert("CN=test-wl-1-master2", 2, false),
            createCert("CN=test-wl-3-master1", 3, false),
            createCert("CN=test-datalake-1-master1", 4, false),
            createCert("CN=ipaserver0.env.xyz.wl.cloudera.site,O=ENV.XYZ.WL.CLOUDERA.SITE", 50, false)
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClient.findAllCert()).thenReturn(certs);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);

    Pair<Set<String>, Map<String, String>> result = cleanupService.revokeCerts(STACK_ID, hosts);

    verify(freeIpaClient, times(1)).revokeCert(2);
    verifyRevokeNotInvoked(freeIpaClient, 1, 3, 4, 50);
    assertEquals(1, result.getFirst().size());
    assertEquals(0, result.getSecond().size());
    assertTrue(result.getFirst().stream().allMatch("CN=test-wl-1-master2"::equals));
}
 
Example #20
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testRevokeCertsWithAlreadyRevokedCertAndNewClusterWithSameName() throws FreeIpaClientException {
    Set<String> hosts = Set.of(
            "test-wl-1-worker0.env.xyz.wl.cloudera.site",
            "test-wl-1-worker1.env.xyz.wl.cloudera.site",
            "test-wl-1-master2.env.xyz.wl.cloudera.site",
            "test-wl-1-compute3.env.xyz.wl.cloudera.site"
    );
    Set<Cert> certs = Set.of(
            createCert("CN=test-wl-2-master2", 1, false),
            createCert("CN=test-wl-1-master2", 2, true),
            createCert("CN=test-wl-1-master2", 20, true),
            createCert("CN=test-wl-1-master2", 21, false),
            createCert("CN=test-wl-3-master1", 3, true),
            createCert("CN=test-datalake-1-master1", 4, false),
            createCert("CN=ipaserver0.env.xyz.wl.cloudera.site,O=ENV.XYZ.WL.CLOUDERA.SITE", 50, false)
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClient.findAllCert()).thenReturn(certs);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);

    Pair<Set<String>, Map<String, String>> result = cleanupService.revokeCerts(STACK_ID, hosts);

    verify(freeIpaClient, times(1)).revokeCert(21);
    verifyRevokeNotInvoked(freeIpaClient, 1, 2, 20, 3, 4, 50);
    assertEquals(1, result.getFirst().size());
    assertEquals(0, result.getSecond().size());
    assertTrue(result.getFirst().stream().allMatch("CN=test-wl-1-master2"::equals));
}
 
Example #21
Source File: VSCodeAdapter.java    From openvsx with Eclipse Public License 2.0 5 votes vote down vote up
private Pair<String, FileResource> getFile(ExtensionVersion extVersion, String assetType) {
    switch (assetType) {
        case FILE_VSIX:
            return Pair.of(
                extVersion.getExtensionFileName(),
                repositories.findFile(extVersion, FileResource.DOWNLOAD)
            );
        case FILE_MANIFEST:
            return Pair.of(
                "package.json",
                repositories.findFile(extVersion, FileResource.MANIFEST)
            );
        case FILE_DETAILS:
            return Pair.of(
                extVersion.getReadmeFileName(),
                repositories.findFile(extVersion, FileResource.README)
            );
        case FILE_LICENSE:
            return Pair.of(
                extVersion.getLicenseFileName(),
                repositories.findFile(extVersion, FileResource.LICENSE)
            );
        case FILE_ICON:
            return Pair.of(
                extVersion.getIconFileName(),
                repositories.findFile(extVersion, FileResource.ICON)
            );
        default:
           return null;
    }
}
 
Example #22
Source File: ServerRemoveHandlerTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
void testSendsFailureMessageWhenSomeServersFail() throws FreeIpaClientException {
    CleanupEvent cleanupEvent =
            new CleanupEvent(STACK_ID, USERS, HOSTS, ROLES, IPS, STATES_TO_SKIP, ACCOUNT_ID, OPERATION_ID, CLUSTER_NAME, ENVIRONMENT_CRN);
    RemoveServersRequest request = new RemoveServersRequest(cleanupEvent);
    Set<String> successList = Set.of("example1.com");
    Map<String, String> errorMap = Map.of("example2.com", "expected exception");
    when(cleanupService.removeServers(any(), any())).thenReturn(Pair.of(successList, errorMap));
    underTest.accept(new Event<>(request));
    verify(cleanupService, times(1)).removeServers(eq(STACK_ID), eq(HOSTS));
    verify(eventBus).notify(eq("REMOVESERVERSRESPONSE_ERROR"), ArgumentMatchers.<Event>any());
}
 
Example #23
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testRevokeCertsWithLongCertAndHostnames() throws FreeIpaClientException {
    Set<String> hosts = Set.of(
            "test-wl-1-worker0.env.xyz.wl.cloudera.site",
            "test-wl-1-worker1.env.xyz.wl.cloudera.site",
            "test-wl-1-master2.env.xyz.wl.cloudera.site",
            "test-wl-1-compute3.env.xyz.wl.cloudera.site"
    );
    Set<Cert> certs = Set.of(
            createCert("CN=test-wl-2-master2.env.xyz.wl.cloudera.site", 1, false),
            createCert("CN=test-wl-1-master2.env.xyz.wl.cloudera.site", 2, false),
            createCert("CN=test-wl-3-master1.env.xyz.wl.cloudera.site", 3, true),
            createCert("CN=test-datalake-1-master1.env.xyz.wl.cloudera.site", 4, false),
            createCert("CN=ipaserver0.env.xyz.wl.cloudera.site,O=ENV.XYZ.WL.CLOUDERA.SITE", 50, false)
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClient.findAllCert()).thenReturn(certs);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);

    Pair<Set<String>, Map<String, String>> result = cleanupService.revokeCerts(STACK_ID, hosts);

    verify(freeIpaClient, times(1)).revokeCert(2);
    verifyRevokeNotInvoked(freeIpaClient, 1, 3, 4, 50);
    assertEquals(1, result.getFirst().size());
    assertEquals(0, result.getSecond().size());
    assertTrue(result.getFirst().stream().allMatch("CN=test-wl-1-master2.env.xyz.wl.cloudera.site"::equals));
}
 
Example #24
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testRevokeCertsWithLongCertAndShortHostnames() throws FreeIpaClientException {
    Set<String> hosts = Set.of(
            "test-wl-1-worker0",
            "test-wl-1-worker1",
            "test-wl-1-master2",
            "test-wl-1-compute3"
    );
    Set<Cert> certs = Set.of(
            createCert("CN=test-wl-2-master2.env.xyz.wl.cloudera.site", 1, false),
            createCert("CN=test-wl-1-master2.env.xyz.wl.cloudera.site", 2, false),
            createCert("CN=test-wl-3-master1.env.xyz.wl.cloudera.site", 3, true),
            createCert("CN=test-datalake-1-master1.env.xyz.wl.cloudera.site", 4, false),
            createCert("CN=ipaserver0.env.xyz.wl.cloudera.site,O=ENV.XYZ.WL.CLOUDERA.SITE", 50, false)
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClient.findAllCert()).thenReturn(certs);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);

    Pair<Set<String>, Map<String, String>> result = cleanupService.revokeCerts(STACK_ID, hosts);

    verify(freeIpaClient, times(1)).revokeCert(2);
    verifyRevokeNotInvoked(freeIpaClient, 1, 3, 4, 50);
    assertEquals(1, result.getFirst().size());
    assertEquals(0, result.getSecond().size());
    assertTrue(result.getFirst().stream().allMatch("CN=test-wl-1-master2.env.xyz.wl.cloudera.site"::equals));
}
 
Example #25
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testRevokeCertsWhenExceptionOccurredDuringRevoke() throws FreeIpaClientException {
    Set<String> hosts = Set.of(
            "test-wl-1-worker0.env.xyz.wl.cloudera.site",
            "test-wl-1-worker1.env.xyz.wl.cloudera.site",
            "test-wl-1-master2.env.xyz.wl.cloudera.site",
            "test-wl-1-compute3.env.xyz.wl.cloudera.site"
    );
    Set<Cert> certs = Set.of(
            createCert("CN=test-wl-2-master2", 1, false),
            createCert("CN=test-wl-1-master2", 2, false),
            createCert("CN=test-wl-3-master1", 3, true),
            createCert("CN=test-datalake-1-master1", 4, false),
            createCert("CN=ipaserver0.env.xyz.wl.cloudera.site,O=ENV.XYZ.WL.CLOUDERA.SITE", 50, false)
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClient.findAllCert()).thenReturn(certs);
    doThrow(new FreeIpaClientException("Cannot connect to FreeIPA")).when(freeIpaClient).revokeCert(2);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);

    Pair<Set<String>, Map<String, String>> result = cleanupService.revokeCerts(STACK_ID, hosts);

    verifyRevokeNotInvoked(freeIpaClient, 1, 3, 4, 50);
    assertEquals(0, result.getFirst().size());
    assertEquals(1, result.getSecond().size());
    assertEquals("Cannot connect to FreeIPA", result.getSecond().get("CN=test-wl-1-master2"));
}
 
Example #26
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveUsersForCluster() throws FreeIpaClientException {
    Set<String> usersNames = Set.of(
            "ldapbind-test-wl-1",
            "kerberosbind-test-wl-1");
    Set<User> ipaUsers = Set.of(
            createUser("ldapbind-test-wl-1"),
            createUser("ldapbind-test-wl-2"),
            createUser("kerberosbind-test-wl-1"),
            createUser("kerberosbind-test-wl-2"),
            createUser("mockuser0"),
            createUser("csso_khorvath")
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);
    when(freeIpaClient.userFindAll()).thenReturn(ipaUsers);
    when(stackService.getStackById(anyLong())).thenReturn(createStack());

    Pair<Set<String>, Map<String, String>> result = cleanupService.removeUsers(STACK_ID, usersNames, "test-wl-1", ENV_CRN);

    verify(freeIpaClient, times(1)).deleteUser("ldapbind-test-wl-1");
    verify(freeIpaClient, times(1)).deleteUser("kerberosbind-test-wl-1");
    verifyUserDeleteNotInvoked(freeIpaClient, "ldapbind-test-wl-2", "kerberosbind-test-wl-2", "mockuser0", "csso_khorvath");
    assertEquals(2, result.getFirst().size());
    assertTrue(result.getFirst().stream().anyMatch("ldapbind-test-wl-1"::equals));
    assertTrue(result.getFirst().stream().anyMatch("kerberosbind-test-wl-1"::equals));
    verify(kerberosConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1");
    verify(ldapConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1");
}
 
Example #27
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveUsersWhenNoClusterNameProvided() throws FreeIpaClientException {
    Set<String> usersNames = Set.of(
            "ldapbind-test-wl-1",
            "kerberosbind-test-wl-1");
    Set<User> ipaUsers = Set.of(
            createUser("ldapbind-test-wl-1"),
            createUser("ldapbind-test-wl-2"),
            createUser("kerberosbind-test-wl-1"),
            createUser("kerberosbind-test-wl-2"),
            createUser("mockuser0"),
            createUser("csso_khorvath")
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);
    when(freeIpaClient.userFindAll()).thenReturn(ipaUsers);

    Pair<Set<String>, Map<String, String>> result = cleanupService.removeUsers(STACK_ID, usersNames, "", ENV_CRN);

    verify(freeIpaClient, times(1)).deleteUser("ldapbind-test-wl-1");
    verify(freeIpaClient, times(1)).deleteUser("kerberosbind-test-wl-1");
    verifyUserDeleteNotInvoked(freeIpaClient, "ldapbind-test-wl-2", "kerberosbind-test-wl-2", "mockuser0", "csso_khorvath");
    assertEquals(2, result.getFirst().size());
    assertTrue(result.getFirst().stream().anyMatch("ldapbind-test-wl-1"::equals));
    assertTrue(result.getFirst().stream().anyMatch("kerberosbind-test-wl-1"::equals));
    verify(kerberosConfigService, times(0)).delete("envCrn", "accountId", "test-wl-1");
    verify(ldapConfigService, times(0)).delete("envCrn", "accountId", "test-wl-1");
}
 
Example #28
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveUsersWhenNoClusterNameProvidedAndDeleteFails() throws FreeIpaClientException {
    Set<String> usersNames = Set.of(
            "ldapbind-test-wl-1",
            "kerberosbind-test-wl-1");
    Set<User> ipaUsers = Set.of(
            createUser("ldapbind-test-wl-1"),
            createUser("ldapbind-test-wl-2"),
            createUser("kerberosbind-test-wl-1"),
            createUser("kerberosbind-test-wl-2"),
            createUser("mockuser0"),
            createUser("csso_khorvath")
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);
    when(freeIpaClient.userFindAll()).thenReturn(ipaUsers);
    doThrow(new FreeIpaClientException("Connection failed")).when(freeIpaClient).deleteUser(anyString());

    Pair<Set<String>, Map<String, String>> result = cleanupService.removeUsers(STACK_ID, usersNames, "", ENV_CRN);

    verify(freeIpaClient, times(1)).deleteUser("ldapbind-test-wl-1");
    verify(freeIpaClient, times(1)).deleteUser("kerberosbind-test-wl-1");
    verifyUserDeleteNotInvoked(freeIpaClient, "ldapbind-test-wl-2", "kerberosbind-test-wl-2", "mockuser0", "csso_khorvath");
    assertEquals(0, result.getFirst().size());
    assertEquals(2, result.getSecond().size());
    assertEquals("Connection failed", result.getSecond().get("ldapbind-test-wl-1"));
    assertEquals("Connection failed", result.getSecond().get("kerberosbind-test-wl-1"));
    verify(kerberosConfigService, times(0)).delete("envCrn", "accountId", "test-wl-1");
    verify(ldapConfigService, times(0)).delete("envCrn", "accountId", "test-wl-1");
}
 
Example #29
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveUsersWhenKerberosConfigAlreadyDeleted() throws FreeIpaClientException {
    Set<String> usersNames = Set.of(
            "ldapbind-test-wl-1",
            "kerberosbind-test-wl-1");
    Set<User> ipaUsers = Set.of(
            createUser("ldapbind-test-wl-1"),
            createUser("ldapbind-test-wl-2"),
            createUser("kerberosbind-test-wl-1"),
            createUser("kerberosbind-test-wl-2"),
            createUser("mockuser0"),
            createUser("csso_khorvath")
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);
    when(freeIpaClient.userFindAll()).thenReturn(ipaUsers);
    when(stackService.getStackById(anyLong())).thenReturn(createStack());
    doThrow(new NotFoundException("Kerberos config not found")).when(kerberosConfigService).delete("envCrn", "accountId", "test-wl-1");

    Pair<Set<String>, Map<String, String>> result = cleanupService.removeUsers(STACK_ID, usersNames, "test-wl-1", ENV_CRN);

    verify(freeIpaClient, times(1)).deleteUser("ldapbind-test-wl-1");
    verify(freeIpaClient, times(1)).deleteUser("kerberosbind-test-wl-1");
    verifyUserDeleteNotInvoked(freeIpaClient, "ldapbind-test-wl-2", "kerberosbind-test-wl-2", "mockuser0", "csso_khorvath");
    assertEquals(2, result.getFirst().size());
    assertTrue(result.getFirst().stream().anyMatch("ldapbind-test-wl-1"::equals));
    assertTrue(result.getFirst().stream().anyMatch("kerberosbind-test-wl-1"::equals));
    verify(kerberosConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1");
    verify(ldapConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1");
}
 
Example #30
Source File: CleanupServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveUsersWhenLdapConfigAlreadyDeleted() throws FreeIpaClientException {
    Set<String> usersNames = Set.of(
            "ldapbind-test-wl-1",
            "kerberosbind-test-wl-1");
    Set<User> ipaUsers = Set.of(
            createUser("ldapbind-test-wl-1"),
            createUser("ldapbind-test-wl-2"),
            createUser("kerberosbind-test-wl-1"),
            createUser("kerberosbind-test-wl-2"),
            createUser("mockuser0"),
            createUser("csso_khorvath")
    );
    FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);
    when(freeIpaClient.userFindAll()).thenReturn(ipaUsers);
    when(stackService.getStackById(anyLong())).thenReturn(createStack());
    doThrow(new NotFoundException("Ldap config not found")).when(ldapConfigService).delete("envCrn", "accountId", "test-wl-1");

    Pair<Set<String>, Map<String, String>> result = cleanupService.removeUsers(STACK_ID, usersNames, "test-wl-1", ENV_CRN);

    verify(freeIpaClient, times(1)).deleteUser("ldapbind-test-wl-1");
    verify(freeIpaClient, times(1)).deleteUser("kerberosbind-test-wl-1");
    verifyUserDeleteNotInvoked(freeIpaClient, "ldapbind-test-wl-2", "kerberosbind-test-wl-2", "mockuser0", "csso_khorvath");
    assertEquals(2, result.getFirst().size());
    assertTrue(result.getFirst().stream().anyMatch("ldapbind-test-wl-1"::equals));
    assertTrue(result.getFirst().stream().anyMatch("kerberosbind-test-wl-1"::equals));
    verify(kerberosConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1");
    verify(ldapConfigService, times(1)).delete("envCrn", "accountId", "test-wl-1");
}