@Test public void testGetResources_KerberosSpecificProperties_NoKDCValidation() throws Exception{ AmbariManagementController managementController = createMock(AmbariManagementController.class); Clusters clusters = createNiceMock(Clusters.class); Cluster cluster = createNiceMock(Cluster.class); Service service0 = createNiceMock(Service.class); ServiceResponse serviceResponse0 = createNiceMock(ServiceResponse.class); StackId stackId = createNiceMock(StackId.class); ServiceFactory serviceFactory = createNiceMock(ServiceFactory.class); AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class); KerberosHelper kerberosHelper = createStrictMock(KerberosHelper.class); Map<String, Service> allResponseMap = new HashMap<String, Service>(); allResponseMap.put("KERBEROS", service0); expect(managementController.getClusters()).andReturn(clusters).anyTimes(); expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes(); expect(managementController.getHostComponents(EasyMock.<Set<ServiceComponentHostRequest>>anyObject())). andReturn(Collections.<ServiceComponentHostResponse>emptySet()).anyTimes(); expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes(); expect(cluster.getServices()).andReturn(allResponseMap).anyTimes(); expect(cluster.getService("KERBEROS")).andReturn(service0); expect(service0.convertToResponse()).andReturn(serviceResponse0).anyTimes(); expect(service0.getName()).andReturn("Service100").anyTimes(); expect(serviceResponse0.getClusterName()).andReturn("Cluster100").anyTimes(); expect(serviceResponse0.getServiceName()).andReturn("KERBEROS").anyTimes(); replay(managementController, clusters, cluster, service0, serviceResponse0, ambariMetaInfo, stackId, serviceFactory, kerberosHelper); SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator()); ResourceProvider provider = getServiceProvider(managementController); Class<?> c = provider.getClass(); Field f = c.getDeclaredField("kerberosHelper"); f.setAccessible(true); f.set(provider, kerberosHelper); Predicate predicate = new PredicateBuilder().property(ServiceResourceProvider.SERVICE_CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").and(). property(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID).equals("KERBEROS").toPredicate(); Request request = PropertyHelper.getReadRequest("ServiceInfo"); Set<Resource> resources = provider.getResources(request, predicate); Assert.assertEquals(1, resources.size()); for (Resource resource : resources) { Assert.assertEquals("Cluster100", resource.getPropertyValue(ServiceResourceProvider.SERVICE_CLUSTER_NAME_PROPERTY_ID)); Assert.assertEquals("KERBEROS", resource.getPropertyValue(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID)); } verify(managementController, clusters, cluster, service0, serviceResponse0, ambariMetaInfo, stackId, serviceFactory, kerberosHelper); }
protected Set<ServiceResponse> getServices(Set<ServiceRequest> requests) throws AmbariException { Set<ServiceResponse> response = new HashSet<ServiceResponse>(); for (ServiceRequest request : requests) { try { response.addAll(getServices(request)); } catch (ServiceNotFoundException e) { if (requests.size() == 1) { throw e; } } } return response; }
ServiceResourceProvider extends AbstractControllerResourceProvider { protected Set<ServiceResponse> getServices(Set<ServiceRequest> requests) throws AmbariException { Set<ServiceResponse> response = new HashSet<ServiceResponse>(); for (ServiceRequest request : requests) { try { response.addAll(getServices(request)); } catch (ServiceNotFoundException e) { if (requests.size() == 1) { throw e; } } } return response; } }
ServiceResourceProvider extends AbstractControllerResourceProvider { protected Set<ServiceResponse> getServices(Set<ServiceRequest> requests) throws AmbariException { Set<ServiceResponse> response = new HashSet<ServiceResponse>(); for (ServiceRequest request : requests) { try { response.addAll(getServices(request)); } catch (ServiceNotFoundException e) { if (requests.size() == 1) { throw e; } } } return response; } @AssistedInject  ServiceResourceProvider(@Assisted Set<String> propertyIds,
                          @Assisted Map<Resource.Type, String> keyPropertyIds,
                          @Assisted AmbariManagementController managementController,
                          MaintenanceStateHelper maintenanceStateHelper); }
ServiceResourceProvider extends AbstractControllerResourceProvider { protected Set<ServiceResponse> getServices(Set<ServiceRequest> requests) throws AmbariException { Set<ServiceResponse> response = new HashSet<ServiceResponse>(); for (ServiceRequest request : requests) { try { response.addAll(getServices(request)); } catch (ServiceNotFoundException e) { if (requests.size() == 1) { throw e; } } } return response; } @AssistedInject  ServiceResourceProvider(@Assisted Set<String> propertyIds,
                          @Assisted Map<Resource.Type, String> keyPropertyIds,
                          @Assisted AmbariManagementController managementController,
                          MaintenanceStateHelper maintenanceStateHelper); @Override Set<String> checkPropertyIds(Set<String> propertyIds); void createServices(Set<ServiceRequest> requests); }
ServiceResourceProvider extends AbstractControllerResourceProvider { protected Set<ServiceResponse> getServices(Set<ServiceRequest> requests) throws AmbariException { Set<ServiceResponse> response = new HashSet<ServiceResponse>(); for (ServiceRequest request : requests) { try { response.addAll(getServices(request)); } catch (ServiceNotFoundException e) { if (requests.size() == 1) { throw e; } } } return response; } @AssistedInject  ServiceResourceProvider(@Assisted Set<String> propertyIds,
                          @Assisted Map<Resource.Type, String> keyPropertyIds,
                          @Assisted AmbariManagementController managementController,
                          MaintenanceStateHelper maintenanceStateHelper); @Override Set<String> checkPropertyIds(Set<String> propertyIds); void createServices(Set<ServiceRequest> requests); static final String SERVICE_CLUSTER_NAME_PROPERTY_ID; static final String SERVICE_SERVICE_NAME_PROPERTY_ID; static final String SERVICE_SERVICE_STATE_PROPERTY_ID; static final String SERVICE_MAINTENANCE_STATE_PROPERTY_ID; static final String SERVICE_CREDENTIAL_STORE_SUPPORTED_PROPERTY_ID; static final String SERVICE_CREDENTIAL_STORE_ENABLED_PROPERTY_ID; static final String SERVICE_ATTRIBUTES_PROPERTY_ID; }