Search in sources :

Example 6 with PackageInfo

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);
}
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 7 with PackageInfo

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());
    }
}
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 8 with PackageInfo

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();
    }
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) PackageInfo(com.sequenceiq.cloudbreak.common.model.PackageInfo) List(java.util.List)

Example 9 with PackageInfo

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;
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) Logger(org.slf4j.Logger) PackageInfo(com.sequenceiq.cloudbreak.common.model.PackageInfo) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) ConfigurationProperties(org.springframework.boot.context.properties.ConfigurationProperties) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Inject(javax.inject.Inject) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) Component(org.springframework.stereotype.Component) HashMultimap(com.google.common.collect.HashMultimap) ImagePackageVersion(com.sequenceiq.cloudbreak.cloud.model.catalog.ImagePackageVersion) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Map(java.util.Map) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Package(com.sequenceiq.cloudbreak.service.cluster.Package) Optional(java.util.Optional) PackageName(com.sequenceiq.cloudbreak.service.cluster.PackageName) Optional(java.util.Optional) List(java.util.List) Package(com.sequenceiq.cloudbreak.service.cluster.Package) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 10 with PackageInfo

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;
}
Also used : PackageInfo(com.sequenceiq.cloudbreak.common.model.PackageInfo)

Aggregations

PackageInfo (com.sequenceiq.cloudbreak.common.model.PackageInfo)10 ArrayList (java.util.ArrayList)5 List (java.util.List)5 PackageVersionResponse (com.sequenceiq.cloudbreak.orchestrator.salt.domain.PackageVersionResponse)3 HashMap (java.util.HashMap)3 Optional (java.util.Optional)3 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)2 HostList (com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList)2 Map (java.util.Map)2 Test (org.junit.Test)2 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 ImagePackageVersion (com.sequenceiq.cloudbreak.cloud.model.catalog.ImagePackageVersion)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)1 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)1 GatewayConfigService (com.sequenceiq.cloudbreak.service.GatewayConfigService)1 Package (com.sequenceiq.cloudbreak.service.cluster.Package)1 PackageName (com.sequenceiq.cloudbreak.service.cluster.PackageName)1