@Test public void testGetResources_Status_Healthy() throws Exception { Resource.Type type = Resource.Type.Host; Injector injector = createInjector(); AmbariManagementController managementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = injector.getInstance(Clusters.class); Cluster cluster = createMock(Cluster.class); HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class); AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class); ComponentInfo componentInfo = createNiceMock(ComponentInfo.class); Host host100 = createMockHost("Host100", "Cluster100", null, "HEALTHY", "RECOVERABLE", null); ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class); ResourceProvider hostResourceProvider = getHostProvider(injector); AbstractControllerResourceProvider.init(resourceProviderFactory); Set<Cluster> clusterSet = new HashSet<Cluster>(); clusterSet.add(cluster); ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component100", "Component 100", "Host100", "Host100", "STARTED", "", null, null, null); ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component102", "Component 102", "Host100", "Host100", "STARTED", "", null, null, null); ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component103", "Component 103", "Host100", "Host100", "STARTED", "", null, null, null); Set<ServiceComponentHostResponse> responses = new HashSet<ServiceComponentHostResponse>(); responses.add(shr1); responses.add(shr2); responses.add(shr3); expect(managementController.getClusters()).andReturn(clusters).anyTimes(); expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes(); expect(managementController.getHostComponents(EasyMock.<Set<ServiceComponentHostRequest>>anyObject())) .andReturn(responses).anyTimes(); expect(host100.getMaintenanceState(2)).andReturn(MaintenanceState.OFF).anyTimes(); expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes(); expect(clusters.getClustersForHost("Host100")).andReturn(clusterSet).anyTimes(); expect(clusters.getHosts()).andReturn(Arrays.asList(host100)).anyTimes(); expect(cluster.getClusterId()).andReturn(2L).anyTimes(); expect(cluster.getDesiredConfigs()).andReturn(new HashMap<String, DesiredConfig>()).anyTimes(); expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes(); expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes(); expect(ambariMetaInfo.getComponent((String) anyObject(), (String) anyObject(), (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes(); expect(componentInfo.getCategory()).andReturn("MASTER").anyTimes(); expect(resourceProviderFactory.getHostResourceProvider(EasyMock.<Set<String>>anyObject(), EasyMock.<Map<Resource.Type, String>>anyObject(), eq(managementController))).andReturn(hostResourceProvider).anyTimes(); Set<String> propertyIds = new HashSet<String>(); propertyIds.add(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID); propertyIds.add(HostResourceProvider.HOST_NAME_PROPERTY_ID); propertyIds.add(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID); Predicate predicate = buildPredicate("Cluster100", null); Request request = PropertyHelper.getReadRequest(propertyIds); replayAll(); SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator()); ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider( type, PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type), managementController); Set<Resource> resources = provider.getResources(request, predicate); Assert.assertEquals(1, resources.size()); for (Resource resource : resources) { String clusterName = (String) resource.getPropertyValue(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID); Assert.assertEquals("Cluster100", clusterName); String status = (String) resource.getPropertyValue(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID); Assert.assertEquals("HEALTHY", status); } verifyAll(); }
protected Set<HostResponse> getHosts(Set<HostRequest> requests) throws AmbariException { Set<HostResponse> response = new HashSet<HostResponse>(); AmbariManagementController controller = getManagementController(); for (HostRequest request : requests) { try { response.addAll(getHosts(controller, request)); } catch (HostNotFoundException e) { if (requests.size() == 1) { throw e; } } } return response; }
HostResourceProvider extends AbstractControllerResourceProvider { protected Set<HostResponse> getHosts(Set<HostRequest> requests) throws AmbariException { Set<HostResponse> response = new HashSet<HostResponse>(); AmbariManagementController controller = getManagementController(); for (HostRequest request : requests) { try { response.addAll(getHosts(controller, request)); } catch (HostNotFoundException e) { if (requests.size() == 1) { throw e; } } } return response; } }
HostResourceProvider extends AbstractControllerResourceProvider { protected Set<HostResponse> getHosts(Set<HostRequest> requests) throws AmbariException { Set<HostResponse> response = new HashSet<HostResponse>(); AmbariManagementController controller = getManagementController(); for (HostRequest request : requests) { try { response.addAll(getHosts(controller, request)); } catch (HostNotFoundException e) { if (requests.size() == 1) { throw e; } } } return response; } @AssistedInject  HostResourceProvider(@Assisted Set<String> propertyIds,
                       @Assisted Map<Resource.Type, String> keyPropertyIds,
                       @Assisted AmbariManagementController managementController); }
HostResourceProvider extends AbstractControllerResourceProvider { protected Set<HostResponse> getHosts(Set<HostRequest> requests) throws AmbariException { Set<HostResponse> response = new HashSet<HostResponse>(); AmbariManagementController controller = getManagementController(); for (HostRequest request : requests) { try { response.addAll(getHosts(controller, request)); } catch (HostNotFoundException e) { if (requests.size() == 1) { throw e; } } } return response; } @AssistedInject  HostResourceProvider(@Assisted Set<String> propertyIds,
                       @Assisted Map<Resource.Type, String> keyPropertyIds,
                       @Assisted AmbariManagementController managementController); @Override Set<String> checkPropertyIds(Set<String> propertyIds); synchronized void createHosts(Request request); RequestStatusResponse install(final String cluster, final String hostname, Collection<String> skipInstallForComponents, Collection<String> dontSkipInstallForComponents, final boolean skipFailure); RequestStatusResponse start(final String cluster, final String hostname); static void setTopologyManager(TopologyManager topologyManager); }
HostResourceProvider extends AbstractControllerResourceProvider { protected Set<HostResponse> getHosts(Set<HostRequest> requests) throws AmbariException { Set<HostResponse> response = new HashSet<HostResponse>(); AmbariManagementController controller = getManagementController(); for (HostRequest request : requests) { try { response.addAll(getHosts(controller, request)); } catch (HostNotFoundException e) { if (requests.size() == 1) { throw e; } } } return response; } @AssistedInject  HostResourceProvider(@Assisted Set<String> propertyIds,
                       @Assisted Map<Resource.Type, String> keyPropertyIds,
                       @Assisted AmbariManagementController managementController); @Override Set<String> checkPropertyIds(Set<String> propertyIds); synchronized void createHosts(Request request); RequestStatusResponse install(final String cluster, final String hostname, Collection<String> skipInstallForComponents, Collection<String> dontSkipInstallForComponents, final boolean skipFailure); RequestStatusResponse start(final String cluster, final String hostname); static void setTopologyManager(TopologyManager topologyManager); static final String HOST_CLUSTER_NAME_PROPERTY_ID; static final String HOST_NAME_PROPERTY_ID; static final String HOST_PUBLIC_NAME_PROPERTY_ID; static final String HOST_IP_PROPERTY_ID; static final String HOST_TOTAL_MEM_PROPERTY_ID; static final String HOST_CPU_COUNT_PROPERTY_ID; static final String HOST_PHYSICAL_CPU_COUNT_PROPERTY_ID; static final String HOST_OS_ARCH_PROPERTY_ID; static final String HOST_OS_TYPE_PROPERTY_ID; static final String HOST_OS_FAMILY_PROPERTY_ID; static final String HOST_RACK_INFO_PROPERTY_ID; static final String HOST_LAST_HEARTBEAT_TIME_PROPERTY_ID; static final String HOST_LAST_REGISTRATION_TIME_PROPERTY_ID; static final String HOST_DISK_INFO_PROPERTY_ID; static final String HOST_HOST_STATUS_PROPERTY_ID; static final String HOST_MAINTENANCE_STATE_PROPERTY_ID; static final String HOST_HOST_HEALTH_REPORT_PROPERTY_ID; static final String HOST_RECOVERY_REPORT_PROPERTY_ID; static final String HOST_RECOVERY_SUMMARY_PROPERTY_ID; static final String HOST_STATE_PROPERTY_ID; static final String HOST_LAST_AGENT_ENV_PROPERTY_ID; static final String HOST_DESIRED_CONFIGS_PROPERTY_ID; static final String BLUEPRINT_PROPERTY_ID; static final String HOSTGROUP_PROPERTY_ID; static final String HOST_NAME_NO_CATEGORY_PROPERTY_ID; static final String HOST_COUNT_PROPERTY_ID; static final String HOST_PREDICATE_PROPERTY_ID; static final String HOST_RACK_INFO_NO_CATEGORY_PROPERTY_ID; }