use of com.sequenceiq.cloudbreak.common.model.PackageInfo 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.common.model.PackageInfo 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.common.model.PackageInfo in project cloudbreak by hortonworks.
the class CmServerQueryService method queryCmVersion.
/**
* Will query all the nodes for the installed CM version
* @param stack The stack, with metadata to be able to build the client to query package versions
* @return The actual CM version, in format version-build number e.g. 7.2.2-13072522
*/
Optional<String> queryCmVersion(Stack stack) {
try {
Map<String, List<PackageInfo>> packageVersions = cmVersionQueryService.queryCmPackageInfo(stack);
PackageInfo cmPackageInfo = cmVersionQueryService.checkCmPackageInfoConsistency(packageVersions);
String version = cmPackageInfo.getFullVersion();
LOGGER.debug("Reading CM version info, found version: {}", version);
return Optional.of(version);
} catch (CloudbreakOrchestratorFailedException e) {
LOGGER.warn("Encountered error during reading CM version info", e);
return Optional.empty();
}
}
use of com.sequenceiq.cloudbreak.common.model.PackageInfo in project cloudbreak by hortonworks.
the class CmVersionQueryService method queryCmPackageInfo.
/**
* Will query all CM related package versions (CM server and CM agent as well) from the nodes.
* <p>
*
* @param stack The stack, with metadata to be able to build the client to query package versions
* @return List of package info found in each host (map key is host fqdn)
*/
Map<String, List<PackageInfo>> queryCmPackageInfo(Stack stack) throws CloudbreakOrchestratorFailedException {
GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
Map<String, Optional<String>> packageMap = packages.stream().filter(aPackage -> aPackage.getName().equals(ImagePackageVersion.CM.getKey())).map(Package::getPkg).flatMap(List::stream).collect(Collectors.toMap(PackageName::getName, packageName -> Optional.ofNullable(packageName.getPattern())));
Map<String, List<PackageInfo>> fullPackageVersionsFromAllHosts = hostOrchestrator.getFullPackageVersionsFromAllHosts(gatewayConfig, packageMap);
LOGGER.debug("Reading CM package info, found packages: " + fullPackageVersionsFromAllHosts);
return fullPackageVersionsFromAllHosts;
}
use of com.sequenceiq.cloudbreak.common.model.PackageInfo in project cloudbreak by hortonworks.
the class CmVersionQueryServiceTest method getPackageInfo.
private PackageInfo getPackageInfo(String name, String version, String buildNumber) {
PackageInfo packageInfo = new PackageInfo();
packageInfo.setName(name);
packageInfo.setVersion(version);
packageInfo.setBuildNumber(buildNumber);
return packageInfo;
}
Aggregations