@Test public void testCreateRequestSchedule() throws Exception { AmbariManagementController managementController = createMock(AmbariManagementController.class); RequestStatusResponse response = createNiceMock(RequestStatusResponse.class); Clusters clusters = createNiceMock(Clusters.class); Cluster cluster = createNiceMock(Cluster.class); RequestExecutionFactory executionFactory = createNiceMock (RequestExecutionFactory.class); RequestExecution requestExecution = createNiceMock(RequestExecution.class); ExecutionScheduleManager executionScheduleManager = createNiceMock (ExecutionScheduleManager.class); expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes(); expect(managementController.getClusters()).andReturn(clusters); expect(managementController.getExecutionScheduleManager()).andReturn (executionScheduleManager).anyTimes(); expect(managementController.getRequestExecutionFactory()).andReturn (executionFactory); expect(managementController.getAuthName()).andReturn("admin").anyTimes(); expect(managementController.getAuthId()).andReturn(1).anyTimes(); Capture<Cluster> clusterCapture = EasyMock.newCapture(); Capture<Batch> batchCapture = EasyMock.newCapture(); Capture<Schedule> scheduleCapture = EasyMock.newCapture(); expect(executionFactory.createNew(capture(clusterCapture), capture(batchCapture), capture(scheduleCapture))).andReturn(requestExecution); replay(managementController, clusters, cluster, executionFactory, requestExecution, response, executionScheduleManager); RequestScheduleResourceProvider resourceProvider = getResourceProvider (managementController); Set<Map<String, Object>> propertySet = new LinkedHashSet<Map<String, Object>>(); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put(RequestScheduleResourceProvider .REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID, "Cluster100"); properties.put(RequestScheduleResourceProvider .REQUEST_SCHEDULE_DESC_PROPERTY_ID, "some description"); properties.put(RequestScheduleResourceProvider .SCHEDULE_DAY_OF_WEEK_PROPERTY_ID, "MON"); properties.put(RequestScheduleResourceProvider .SCHEDULE_MINUTES_PROPERTY_ID, "2"); properties.put(RequestScheduleResourceProvider .SCHEDULE_END_TIME_PROPERTY_ID, "2013-11-18T14:29:29-08:00"); properties.put(RequestScheduleResourceProvider .SCHEDULE_DAYS_OF_MONTH_PROPERTY_ID, "*"); HashSet<Map<String, Object>> batch = new HashSet<Map<String, Object>>(); Map<String, Object> batchSettings = new HashMap<String, Object>(); batchSettings.put(RequestScheduleResourceProvider .REQUEST_SCHEDULE_BATCH_SEPARATION_PROPERTY_ID, "15"); Map<String, Object> batchRequests = new HashMap<String, Object>(); HashSet<Map<String, Object>> requestSet = new HashSet<Map<String, Object>>(); Map<String, Object> request1 = new HashMap<String, Object>(); Map<String, Object> request2 = new HashMap<String, Object>(); request1.put(RequestScheduleResourceProvider .BATCH_REQUEST_TYPE_PROPERTY_ID, BatchRequest.Type.PUT.name()); request1.put(RequestScheduleResourceProvider .BATCH_REQUEST_ORDER_ID_PROPERTY_ID, "20"); request1.put(RequestScheduleResourceProvider .BATCH_REQUEST_URI_PROPERTY_ID, "SomeUpdateUri"); request1.put(RequestScheduleResourceProvider .BATCH_REQUEST_BODY_PROPERTY_ID, "data1"); request2.put(RequestScheduleResourceProvider .BATCH_REQUEST_TYPE_PROPERTY_ID, BatchRequest.Type.DELETE.name()); request2.put(RequestScheduleResourceProvider .BATCH_REQUEST_ORDER_ID_PROPERTY_ID, "22"); request2.put(RequestScheduleResourceProvider .BATCH_REQUEST_URI_PROPERTY_ID, "SomeDeleteUri"); requestSet.add(request1); requestSet.add(request2); batchRequests.put(RequestScheduleResourceProvider .REQUEST_SCHEDULE_BATCH_REQUESTS_PROPERTY_ID, requestSet); batch.add(batchSettings); batch.add(batchRequests); properties.put(RequestScheduleResourceProvider .REQUEST_SCHEDULE_BATCH_PROPERTY_ID, batch); propertySet.add(properties); Request request = PropertyHelper.getCreateRequest(propertySet, null); resourceProvider.createResources(request); verify(managementController, clusters, cluster, executionFactory, requestExecution, response, executionScheduleManager); List<BatchRequest> testRequests = batchCapture.getValue().getBatchRequests(); Assert.assertNotNull(testRequests); BatchRequest deleteReq = null; BatchRequest putReq = null; for (BatchRequest testBatchRequest : testRequests) { if (testBatchRequest.getType().equals(BatchRequest.Type.DELETE.name())) { deleteReq = testBatchRequest; } else { putReq = testBatchRequest; } } Assert.assertNotNull(deleteReq); Assert.assertNotNull(putReq); Assert.assertEquals("data1", putReq.getBody()); Assert.assertNull(deleteReq.getBody()); }
@Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { final Set<RequestScheduleRequest> requests = new HashSet<RequestScheduleRequest>(); for (Map<String, Object> propertyMap : request.getProperties()) { requests.add(getRequestScheduleRequest(propertyMap)); } Set<RequestScheduleResponse> responses = createResources(new Command<Set<RequestScheduleResponse>>() { @Override public Set<RequestScheduleResponse> invoke() throws AmbariException { return createRequestSchedules(requests); } }); notifyCreate(Resource.Type.RequestSchedule, request); Set<Resource> associatedResources = new HashSet<Resource>(); for (RequestScheduleResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RequestSchedule); resource.setProperty(REQUEST_SCHEDULE_ID_PROPERTY_ID, response.getId()); associatedResources.add(resource); } return getRequestStatus(null, associatedResources); }
RequestScheduleResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { final Set<RequestScheduleRequest> requests = new HashSet<RequestScheduleRequest>(); for (Map<String, Object> propertyMap : request.getProperties()) { requests.add(getRequestScheduleRequest(propertyMap)); } Set<RequestScheduleResponse> responses = createResources(new Command<Set<RequestScheduleResponse>>() { @Override public Set<RequestScheduleResponse> invoke() throws AmbariException { return createRequestSchedules(requests); } }); notifyCreate(Resource.Type.RequestSchedule, request); Set<Resource> associatedResources = new HashSet<Resource>(); for (RequestScheduleResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RequestSchedule); resource.setProperty(REQUEST_SCHEDULE_ID_PROPERTY_ID, response.getId()); associatedResources.add(resource); } return getRequestStatus(null, associatedResources); } }
RequestScheduleResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { final Set<RequestScheduleRequest> requests = new HashSet<RequestScheduleRequest>(); for (Map<String, Object> propertyMap : request.getProperties()) { requests.add(getRequestScheduleRequest(propertyMap)); } Set<RequestScheduleResponse> responses = createResources(new Command<Set<RequestScheduleResponse>>() { @Override public Set<RequestScheduleResponse> invoke() throws AmbariException { return createRequestSchedules(requests); } }); notifyCreate(Resource.Type.RequestSchedule, request); Set<Resource> associatedResources = new HashSet<Resource>(); for (RequestScheduleResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RequestSchedule); resource.setProperty(REQUEST_SCHEDULE_ID_PROPERTY_ID, response.getId()); associatedResources.add(resource); } return getRequestStatus(null, associatedResources); } protected  RequestScheduleResourceProvider(Set<String> propertyIds,
      Map<Resource.Type, String> keyPropertyIds,
        AmbariManagementController managementController); }
RequestScheduleResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { final Set<RequestScheduleRequest> requests = new HashSet<RequestScheduleRequest>(); for (Map<String, Object> propertyMap : request.getProperties()) { requests.add(getRequestScheduleRequest(propertyMap)); } Set<RequestScheduleResponse> responses = createResources(new Command<Set<RequestScheduleResponse>>() { @Override public Set<RequestScheduleResponse> invoke() throws AmbariException { return createRequestSchedules(requests); } }); notifyCreate(Resource.Type.RequestSchedule, request); Set<Resource> associatedResources = new HashSet<Resource>(); for (RequestScheduleResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RequestSchedule); resource.setProperty(REQUEST_SCHEDULE_ID_PROPERTY_ID, response.getId()); associatedResources.add(resource); } return getRequestStatus(null, associatedResources); } protected  RequestScheduleResourceProvider(Set<String> propertyIds,
      Map<Resource.Type, String> keyPropertyIds,
        AmbariManagementController managementController); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); }
RequestScheduleResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { final Set<RequestScheduleRequest> requests = new HashSet<RequestScheduleRequest>(); for (Map<String, Object> propertyMap : request.getProperties()) { requests.add(getRequestScheduleRequest(propertyMap)); } Set<RequestScheduleResponse> responses = createResources(new Command<Set<RequestScheduleResponse>>() { @Override public Set<RequestScheduleResponse> invoke() throws AmbariException { return createRequestSchedules(requests); } }); notifyCreate(Resource.Type.RequestSchedule, request); Set<Resource> associatedResources = new HashSet<Resource>(); for (RequestScheduleResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RequestSchedule); resource.setProperty(REQUEST_SCHEDULE_ID_PROPERTY_ID, response.getId()); associatedResources.add(resource); } return getRequestStatus(null, associatedResources); } protected  RequestScheduleResourceProvider(Set<String> propertyIds,
      Map<Resource.Type, String> keyPropertyIds,
        AmbariManagementController managementController); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate);  }