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;
}
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);
}
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);
}
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());
}
}
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);
}
Aggregations