Search in sources :

Example 1 with PackageVersionResponse

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

the class SaltStates method getSinglePackageVersion.

private static Map<String, PackageInfo> getSinglePackageVersion(SaltConnector sc, String singlePackage, Optional<String> versionPattern) {
    PackageVersionResponse packageVersionResponse = measure(() -> sc.run(Glob.ALL, "pkg.version", LOCAL, PackageVersionResponse.class, singlePackage), LOGGER, "Get package version took {}ms for package [{}] with pattern [{}]", singlePackage, versionPattern);
    Map<String, String> packageVersionsMap = CollectionUtils.isEmpty(packageVersionResponse.getResult()) ? new HashMap<>() : packageVersionResponse.getResult().get(0);
    Map<String, PackageInfo> result = new HashMap<>();
    for (Entry<String, String> e : packageVersionsMap.entrySet()) {
        result.put(e.getKey(), parseVersion(singlePackage, e.getValue(), versionPattern));
    }
    return result;
}
Also used : PackageVersionResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.PackageVersionResponse) HashMap(java.util.HashMap) PackageInfo(com.sequenceiq.cloudbreak.common.model.PackageInfo)

Example 2 with PackageVersionResponse

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

the class SaltStatesTest method testGetPackageVersionWithMorePackagesShouldReturnEmptyMapWhenTheListIsEmptyInResponse.

@Test
public void testGetPackageVersionWithMorePackagesShouldReturnEmptyMapWhenTheListIsEmptyInResponse() {
    // GIVEN
    PackageVersionResponse resp = new PackageVersionResponse();
    when(saltConnector.run(Glob.ALL, "pkg.version", LOCAL, PackageVersionResponse.class, "package1")).thenReturn(resp);
    when(saltConnector.run(Glob.ALL, "pkg.version", LOCAL, PackageVersionResponse.class, "package2")).thenReturn(resp);
    Map<String, Optional<String>> packages = new HashMap<>();
    packages.put("package1", Optional.empty());
    packages.put("package2", Optional.of("(.*)-(.*)"));
    // WHEN
    Map<String, List<PackageInfo>> actualResponse = SaltStates.getPackageVersions(saltConnector, packages);
    // THEN
    assertTrue(actualResponse.size() == 0);
}
Also used : PackageVersionResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.PackageVersionResponse) Optional(java.util.Optional) HashMap(java.util.HashMap) HostList(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with PackageVersionResponse

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

the class SaltStatesTest method testGetPackageVersionsWithMorePackages.

@Test
public void testGetPackageVersionsWithMorePackages() {
    // GIVEN
    Map<String, List<PackageInfo>> pkgVersionsOnHosts = new HashMap<>();
    List<PackageInfo> pkgVersionsOnHost1 = new ArrayList<>();
    pkgVersionsOnHost1.add(new PackageInfo("package1", "1.0"));
    pkgVersionsOnHost1.add(new PackageInfo("package2", "2.0", "3.0A13466743"));
    pkgVersionsOnHosts.put("host1", pkgVersionsOnHost1);
    List<PackageInfo> pkgVersionsOnHost2 = new ArrayList<>();
    pkgVersionsOnHost2.add(new PackageInfo("package1", "2.0"));
    pkgVersionsOnHost2.add(new PackageInfo("package2", "3.0", "3.0A13466743"));
    pkgVersionsOnHosts.put("host2", pkgVersionsOnHost2);
    Map<String, String> pkgVersionsOnHost1Resp = new HashMap<>();
    pkgVersionsOnHost1Resp.put("host1", "1.0");
    pkgVersionsOnHost1Resp.put("host2", "2.0");
    Map<String, String> pkgVersionsOnHost2Resp = new HashMap<>();
    pkgVersionsOnHost2Resp.put("host1", "2.0-3.0A13466743");
    pkgVersionsOnHost2Resp.put("host2", "3.0-3.0A13466743");
    PackageVersionResponse resp1 = new PackageVersionResponse();
    resp1.setResult(Lists.newArrayList(pkgVersionsOnHost1Resp));
    PackageVersionResponse resp2 = new PackageVersionResponse();
    resp2.setResult(Lists.newArrayList(pkgVersionsOnHost2Resp));
    when(saltConnector.run(Glob.ALL, "pkg.version", LOCAL, PackageVersionResponse.class, "package1")).thenReturn(resp1);
    when(saltConnector.run(Glob.ALL, "pkg.version", LOCAL, PackageVersionResponse.class, "package2")).thenReturn(resp2);
    Map<String, Optional<String>> packages = new HashMap<>();
    packages.put("package1", Optional.empty());
    packages.put("package2", Optional.of("(.*)-(.*)"));
    // WHEN
    Map<String, List<PackageInfo>> actualResponse = SaltStates.getPackageVersions(saltConnector, packages);
    // THEN
    Assert.assertEquals(pkgVersionsOnHosts, actualResponse);
}
Also used : PackageVersionResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.PackageVersionResponse) Optional(java.util.Optional) HashMap(java.util.HashMap) PackageInfo(com.sequenceiq.cloudbreak.common.model.PackageInfo) ArrayList(java.util.ArrayList) HostList(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with PackageVersionResponse

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

the class SaltStatesTest method testGetPackageVersionsWithOnePackage.

@Test
public void testGetPackageVersionsWithOnePackage() {
    // GIVEN
    List<Map<String, String>> pkgVersionList = new ArrayList<>();
    Map<String, String> pkgVersionsOnHosts = new HashMap<>();
    pkgVersionsOnHosts.put("host1", "1.0");
    pkgVersionsOnHosts.put("host2", "2.0");
    pkgVersionList.add(pkgVersionsOnHosts);
    PackageVersionResponse resp = new PackageVersionResponse();
    resp.setResult(pkgVersionList);
    when(saltConnector.run(Glob.ALL, "pkg.version", LOCAL, PackageVersionResponse.class, "package")).thenReturn(resp);
    Map<String, Optional<String>> packages = new HashMap<>();
    packages.put("package", Optional.empty());
    // WHEN
    Map<String, List<PackageInfo>> actualResponse = SaltStates.getPackageVersions(saltConnector, packages);
    // THEN
    for (Map.Entry<String, List<PackageInfo>> e : actualResponse.entrySet()) {
        String expectedVersion = pkgVersionsOnHosts.get(e.getKey());
        List<PackageInfo> actualPkgVersions = e.getValue();
        assertEquals(1, actualPkgVersions.size());
        assertEquals(expectedVersion, actualPkgVersions.get(0).getVersion());
    }
}
Also used : PackageVersionResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.PackageVersionResponse) Optional(java.util.Optional) HashMap(java.util.HashMap) PackageInfo(com.sequenceiq.cloudbreak.common.model.PackageInfo) ArrayList(java.util.ArrayList) HostList(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 5 with PackageVersionResponse

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

the class SaltStatesTest method testGetPackageVersionWithOnePackageShouldReturnEmptyMapWhenTheListIsEmptyInResponse.

@Test
public void testGetPackageVersionWithOnePackageShouldReturnEmptyMapWhenTheListIsEmptyInResponse() {
    // GIVEN
    List<Map<String, String>> pkgVersionsList = new ArrayList<>();
    PackageVersionResponse resp = new PackageVersionResponse();
    resp.setResult(pkgVersionsList);
    when(saltConnector.run(Glob.ALL, "pkg.version", LOCAL, PackageVersionResponse.class, "package")).thenReturn(resp);
    Map<String, Optional<String>> packages = new HashMap<>();
    packages.put("package", Optional.empty());
    // WHEN
    Map<String, List<PackageInfo>> actualResponse = SaltStates.getPackageVersions(saltConnector, packages);
    // THEN
    assertTrue(actualResponse.size() == 0);
}
Also used : PackageVersionResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.PackageVersionResponse) Optional(java.util.Optional) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HostList(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

PackageVersionResponse (com.sequenceiq.cloudbreak.orchestrator.salt.domain.PackageVersionResponse)6 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 HostList (com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList)4 List (java.util.List)4 Optional (java.util.Optional)4 Test (org.junit.Test)4 PackageInfo (com.sequenceiq.cloudbreak.common.model.PackageInfo)3 Map (java.util.Map)3 ClouderaManagerDto (com.sequenceiq.mock.clouderamanager.ClouderaManagerDto)1 ApiClusterTemplateHostInfo (com.sequenceiq.mock.swagger.model.ApiClusterTemplateHostInfo)1