RequestScheduleResourceProvider extends AbstractControllerResourceProvider { private synchronized void deleteRequestSchedule(RequestScheduleRequest request) throws AmbariException { if (request.getId() == null) { throw new AmbariException("Id is a required field."); } Clusters clusters = getManagementController().getClusters(); Cluster cluster; try { cluster = clusters.getCluster(request.getClusterName()); } catch (ClusterNotFoundException e) { throw new ParentObjectNotFoundException( "Attempted to delete a request schedule from a cluster which doesn't " + "exist", e); } RequestExecution requestExecution = cluster.getAllRequestExecutions().get(request.getId()); if (requestExecution == null) { throw new AmbariException("Request Schedule not found " + ", clusterName = " + request.getClusterName() + ", description = " + request.getDescription() + ", id = " + request.getId()); } String username = getManagementController().getAuthName(); LOG.info("Disabling Request Schedule " + ", clusterName = " + request.getClusterName() + ", id = " + request.getId() + ", user = " + username); getManagementController().getExecutionScheduleManager() .deleteAllJobs(requestExecution); requestExecution.updateStatus(RequestExecution.Status.DISABLED); } 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);  }
@Test public void testDeleteRequestSchedule() throws Exception { AmbariManagementController managementController = createMock(AmbariManagementController.class); Clusters clusters = createNiceMock(Clusters.class); Cluster cluster = createNiceMock(Cluster.class); RequestExecution requestExecution = createNiceMock(RequestExecution.class); ExecutionScheduleManager executionScheduleManager = createNiceMock (ExecutionScheduleManager.class); Map<Long, RequestExecution> requestExecutionMap = new HashMap<Long, RequestExecution>(); requestExecutionMap.put(1L, requestExecution); expect(managementController.getAuthName()).andReturn("admin").anyTimes(); expect(managementController.getClusters()).andReturn(clusters).anyTimes(); expect(managementController.getExecutionScheduleManager()).andReturn (executionScheduleManager).anyTimes(); expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes(); expect(cluster.getAllRequestExecutions()).andReturn(requestExecutionMap); replay(managementController, clusters, cluster, executionScheduleManager, requestExecution ); RequestScheduleResourceProvider resourceProvider = getResourceProvider (managementController); AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver(); ((ObservableResourceProvider) resourceProvider).addObserver(observer); Predicate predicate = new PredicateBuilder().property (RequestScheduleResourceProvider.REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID) .equals("Cluster100").and().property(RequestScheduleResourceProvider .REQUEST_SCHEDULE_ID_PROPERTY_ID).equals(1L).toPredicate(); resourceProvider.deleteResources(new RequestImpl(null, null, null, null), predicate); ResourceProviderEvent lastEvent = observer.getLastEvent(); Assert.assertNotNull(lastEvent); Assert.assertEquals(Resource.Type.RequestSchedule, lastEvent.getResourceType()); Assert.assertEquals(ResourceProviderEvent.Type.Delete, lastEvent.getType()); Assert.assertEquals(predicate, lastEvent.getPredicate()); Assert.assertNull(lastEvent.getRequest()); verify(managementController, clusters, cluster, executionScheduleManager, requestExecution); }