@Test public void testCreateResources_in_out_of_sync_state() throws Exception { StackId stackId = new StackId("HDP", "2.0.1"); final Host host1 = createNiceMock("host1", Host.class); expect(host1.getHostName()).andReturn("host1").anyTimes(); expect(host1.getOsFamily()).andReturn("redhat6").anyTimes(); replay(host1); Map<String, Host> hostsForCluster = Collections.singletonMap(host1.getHostName(), host1); ServiceComponentHost sch = createMock(ServiceComponentHost.class); List<ServiceComponentHost> schs = Collections.singletonList(sch); ServiceOsSpecific.Package hivePackage = new ServiceOsSpecific.Package(); hivePackage.setName("hive"); List<ServiceOsSpecific.Package> packages = Collections.singletonList(hivePackage); AbstractControllerResourceProvider.init(resourceProviderFactory); Map<String, Map<String, String>> hostConfigTags = new HashMap<>(); expect(configHelper.getEffectiveDesiredTags(anyObject(ClusterImpl.class), anyObject(String.class))).andReturn(hostConfigTags); expect(managementController.getClusters()).andReturn(clusters).anyTimes(); expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes(); expect(managementController.getActionManager()).andReturn(actionManager).anyTimes(); expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes(); expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class), EasyMock.<Map<String, String>>anyObject(), anyObject(String.class))).andReturn(packages).anyTimes(); expect(resourceProviderFactory.getHostResourceProvider(EasyMock.<Set<String>>anyObject(), EasyMock.<Map<Resource.Type, String>>anyObject(), eq(managementController))).andReturn(csvResourceProvider).anyTimes(); expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster); expect(clusters.getHost(anyObject(String.class))).andReturn(host1); expect(cluster.getHosts()).andReturn(hostsForCluster.values()).atLeastOnce(); expect(cluster.getServices()).andReturn(new HashMap<String, Service>()).anyTimes(); expect(cluster.getCurrentStackVersion()).andReturn(stackId); expect(cluster.getServiceComponentHosts(anyObject(String.class))).andReturn(schs).anyTimes(); expect(sch.getServiceName()).andReturn("HIVE").anyTimes(); expect( repositoryVersionDAOMock.findByStackAndVersion( anyObject(StackId.class), anyObject(String.class))).andReturn(repoVersion); expect( hostVersionDAOMock.findByClusterStackVersionAndHost( anyObject(String.class), anyObject(StackId.class), anyObject(String.class), anyObject(String.class))).andReturn( hostVersionEntityMock); expect(hostVersionEntityMock.getState()).andReturn(RepositoryVersionState.OUT_OF_SYNC).anyTimes(); expect(actionManager.getRequestTasks(anyLong())).andReturn(Collections.<HostRoleCommand>emptyList()).anyTimes(); StageUtils.setTopologyManager(injector.getInstance(TopologyManager.class)); StageUtils.setConfiguration(injector.getInstance(Configuration.class)); replay(managementController, response, clusters, resourceProviderFactory, csvResourceProvider, cluster, repositoryVersionDAOMock, configHelper, sch, actionManager, hostVersionEntityMock, hostVersionDAOMock); ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider( type, PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type), managementController); injector.injectMembers(provider); Set<Map<String, Object>> propertySet = new LinkedHashSet<>(); Map<String, Object> properties = new LinkedHashMap<>(); properties.put(HostStackVersionResourceProvider.HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID, "Cluster100"); properties.put(HostStackVersionResourceProvider.HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID, "2.2.0.1-885"); properties.put(HostStackVersionResourceProvider.HOST_STACK_VERSION_STACK_PROPERTY_ID, "HDP"); properties.put(HostStackVersionResourceProvider.HOST_STACK_VERSION_VERSION_PROPERTY_ID, "2.0.1"); properties.put(HostStackVersionResourceProvider.HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID, "host1"); propertySet.add(properties); Request request = PropertyHelper.getCreateRequest(propertySet, null); provider.createResources(request); verify(managementController, response, clusters); }
@Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); String hostName; final String desiredRepoVersion; String stackName; String stackVersion; if (request.getProperties().size() > 1) { throw new UnsupportedOperationException("Multiple requests cannot be executed at the same time."); } Map<String, Object> propertyMap = iterator.next(); Set<String> requiredProperties = Sets.newHashSet( HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID, HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID, HOST_STACK_VERSION_STACK_PROPERTY_ID, HOST_STACK_VERSION_VERSION_PROPERTY_ID); for (String requiredProperty : requiredProperties) { Validate.isTrue(propertyMap.containsKey(requiredProperty), String.format("The required property %s is not defined", requiredProperty)); } String clName = (String) propertyMap.get (HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID); hostName = (String) propertyMap.get(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID); desiredRepoVersion = (String) propertyMap.get(HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID); stackName = (String) propertyMap.get(HOST_STACK_VERSION_STACK_PROPERTY_ID); stackVersion = (String) propertyMap.get(HOST_STACK_VERSION_VERSION_PROPERTY_ID); boolean forceInstallOnNonMemberHost = false; Set<Map<String, String>> componentNames = null; String forceInstallOnNonMemberHostString = (String) propertyMap.get (HOST_STACK_VERSION_FORCE_INSTALL_ON_NON_MEMBER_HOST_PROPERTY_ID); if (BooleanUtils.toBoolean(forceInstallOnNonMemberHostString)) { forceInstallOnNonMemberHost = true; componentNames = (Set<Map<String, String>>) propertyMap.get(HOST_STACK_VERSION_COMPONENT_NAMES_PROPERTY_ID); if (componentNames == null) { throw new IllegalArgumentException("In case " + HOST_STACK_VERSION_FORCE_INSTALL_ON_NON_MEMBER_HOST_PROPERTY_ID + " is set to true, the list of " + "components should be specified in request."); } } RequestStageContainer req = createInstallPackagesRequest(hostName, desiredRepoVersion, stackName, stackVersion, clName, forceInstallOnNonMemberHost, componentNames); return getRequestStatus(req.getRequestStatusResponse()); }
HostStackVersionResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); String hostName; final String desiredRepoVersion; String stackName; String stackVersion; if (request.getProperties().size() > 1) { throw new UnsupportedOperationException("Multiple requests cannot be executed at the same time."); } Map<String, Object> propertyMap = iterator.next(); Set<String> requiredProperties = Sets.newHashSet( HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID, HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID, HOST_STACK_VERSION_STACK_PROPERTY_ID, HOST_STACK_VERSION_VERSION_PROPERTY_ID); for (String requiredProperty : requiredProperties) { Validate.isTrue(propertyMap.containsKey(requiredProperty), String.format("The required property %s is not defined", requiredProperty)); } String clName = (String) propertyMap.get (HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID); hostName = (String) propertyMap.get(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID); desiredRepoVersion = (String) propertyMap.get(HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID); stackName = (String) propertyMap.get(HOST_STACK_VERSION_STACK_PROPERTY_ID); stackVersion = (String) propertyMap.get(HOST_STACK_VERSION_VERSION_PROPERTY_ID); boolean forceInstallOnNonMemberHost = false; Set<Map<String, String>> componentNames = null; String forceInstallOnNonMemberHostString = (String) propertyMap.get (HOST_STACK_VERSION_FORCE_INSTALL_ON_NON_MEMBER_HOST_PROPERTY_ID); if (BooleanUtils.toBoolean(forceInstallOnNonMemberHostString)) { forceInstallOnNonMemberHost = true; componentNames = (Set<Map<String, String>>) propertyMap.get(HOST_STACK_VERSION_COMPONENT_NAMES_PROPERTY_ID); if (componentNames == null) { throw new IllegalArgumentException("In case " + HOST_STACK_VERSION_FORCE_INSTALL_ON_NON_MEMBER_HOST_PROPERTY_ID + " is set to true, the list of " + "components should be specified in request."); } } RequestStageContainer req = createInstallPackagesRequest(hostName, desiredRepoVersion, stackName, stackVersion, clName, forceInstallOnNonMemberHost, componentNames); return getRequestStatus(req.getRequestStatusResponse()); } }
HostStackVersionResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); String hostName; final String desiredRepoVersion; String stackName; String stackVersion; if (request.getProperties().size() > 1) { throw new UnsupportedOperationException("Multiple requests cannot be executed at the same time."); } Map<String, Object> propertyMap = iterator.next(); Set<String> requiredProperties = Sets.newHashSet( HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID, HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID, HOST_STACK_VERSION_STACK_PROPERTY_ID, HOST_STACK_VERSION_VERSION_PROPERTY_ID); for (String requiredProperty : requiredProperties) { Validate.isTrue(propertyMap.containsKey(requiredProperty), String.format("The required property %s is not defined", requiredProperty)); } String clName = (String) propertyMap.get (HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID); hostName = (String) propertyMap.get(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID); desiredRepoVersion = (String) propertyMap.get(HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID); stackName = (String) propertyMap.get(HOST_STACK_VERSION_STACK_PROPERTY_ID); stackVersion = (String) propertyMap.get(HOST_STACK_VERSION_VERSION_PROPERTY_ID); boolean forceInstallOnNonMemberHost = false; Set<Map<String, String>> componentNames = null; String forceInstallOnNonMemberHostString = (String) propertyMap.get (HOST_STACK_VERSION_FORCE_INSTALL_ON_NON_MEMBER_HOST_PROPERTY_ID); if (BooleanUtils.toBoolean(forceInstallOnNonMemberHostString)) { forceInstallOnNonMemberHost = true; componentNames = (Set<Map<String, String>>) propertyMap.get(HOST_STACK_VERSION_COMPONENT_NAMES_PROPERTY_ID); if (componentNames == null) { throw new IllegalArgumentException("In case " + HOST_STACK_VERSION_FORCE_INSTALL_ON_NON_MEMBER_HOST_PROPERTY_ID + " is set to true, the list of " + "components should be specified in request."); } } RequestStageContainer req = createInstallPackagesRequest(hostName, desiredRepoVersion, stackName, stackVersion, clName, forceInstallOnNonMemberHost, componentNames); return getRequestStatus(req.getRequestStatusResponse()); } HostStackVersionResourceProvider(
          AmbariManagementController managementController); }
HostStackVersionResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); String hostName; final String desiredRepoVersion; String stackName; String stackVersion; if (request.getProperties().size() > 1) { throw new UnsupportedOperationException("Multiple requests cannot be executed at the same time."); } Map<String, Object> propertyMap = iterator.next(); Set<String> requiredProperties = Sets.newHashSet( HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID, HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID, HOST_STACK_VERSION_STACK_PROPERTY_ID, HOST_STACK_VERSION_VERSION_PROPERTY_ID); for (String requiredProperty : requiredProperties) { Validate.isTrue(propertyMap.containsKey(requiredProperty), String.format("The required property %s is not defined", requiredProperty)); } String clName = (String) propertyMap.get (HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID); hostName = (String) propertyMap.get(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID); desiredRepoVersion = (String) propertyMap.get(HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID); stackName = (String) propertyMap.get(HOST_STACK_VERSION_STACK_PROPERTY_ID); stackVersion = (String) propertyMap.get(HOST_STACK_VERSION_VERSION_PROPERTY_ID); boolean forceInstallOnNonMemberHost = false; Set<Map<String, String>> componentNames = null; String forceInstallOnNonMemberHostString = (String) propertyMap.get (HOST_STACK_VERSION_FORCE_INSTALL_ON_NON_MEMBER_HOST_PROPERTY_ID); if (BooleanUtils.toBoolean(forceInstallOnNonMemberHostString)) { forceInstallOnNonMemberHost = true; componentNames = (Set<Map<String, String>>) propertyMap.get(HOST_STACK_VERSION_COMPONENT_NAMES_PROPERTY_ID); if (componentNames == null) { throw new IllegalArgumentException("In case " + HOST_STACK_VERSION_FORCE_INSTALL_ON_NON_MEMBER_HOST_PROPERTY_ID + " is set to true, the list of " + "components should be specified in request."); } } RequestStageContainer req = createInstallPackagesRequest(hostName, desiredRepoVersion, stackName, stackVersion, clName, forceInstallOnNonMemberHost, componentNames); return getRequestStatus(req.getRequestStatusResponse()); } HostStackVersionResourceProvider(
          AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); void addRequestedEntities(Set<Resource> resources,
                                   List<HostVersionEntity> requestedEntities,
                                   Set<String> requestedIds,
                                   String clusterName); @Override RequestStatus createResources(Request request); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); }
HostStackVersionResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); String hostName; final String desiredRepoVersion; String stackName; String stackVersion; if (request.getProperties().size() > 1) { throw new UnsupportedOperationException("Multiple requests cannot be executed at the same time."); } Map<String, Object> propertyMap = iterator.next(); Set<String> requiredProperties = Sets.newHashSet( HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID, HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID, HOST_STACK_VERSION_STACK_PROPERTY_ID, HOST_STACK_VERSION_VERSION_PROPERTY_ID); for (String requiredProperty : requiredProperties) { Validate.isTrue(propertyMap.containsKey(requiredProperty), String.format("The required property %s is not defined", requiredProperty)); } String clName = (String) propertyMap.get (HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID); hostName = (String) propertyMap.get(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID); desiredRepoVersion = (String) propertyMap.get(HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID); stackName = (String) propertyMap.get(HOST_STACK_VERSION_STACK_PROPERTY_ID); stackVersion = (String) propertyMap.get(HOST_STACK_VERSION_VERSION_PROPERTY_ID); boolean forceInstallOnNonMemberHost = false; Set<Map<String, String>> componentNames = null; String forceInstallOnNonMemberHostString = (String) propertyMap.get (HOST_STACK_VERSION_FORCE_INSTALL_ON_NON_MEMBER_HOST_PROPERTY_ID); if (BooleanUtils.toBoolean(forceInstallOnNonMemberHostString)) { forceInstallOnNonMemberHost = true; componentNames = (Set<Map<String, String>>) propertyMap.get(HOST_STACK_VERSION_COMPONENT_NAMES_PROPERTY_ID); if (componentNames == null) { throw new IllegalArgumentException("In case " + HOST_STACK_VERSION_FORCE_INSTALL_ON_NON_MEMBER_HOST_PROPERTY_ID + " is set to true, the list of " + "components should be specified in request."); } } RequestStageContainer req = createInstallPackagesRequest(hostName, desiredRepoVersion, stackName, stackVersion, clName, forceInstallOnNonMemberHost, componentNames); return getRequestStatus(req.getRequestStatusResponse()); } HostStackVersionResourceProvider(
          AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); void addRequestedEntities(Set<Resource> resources,
                                   List<HostVersionEntity> requestedEntities,
                                   Set<String> requestedIds,
                                   String clusterName); @Override RequestStatus createResources(Request request); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate);  }