@Test public void testGetEffectiveStateForServiceAlert() throws Exception { Injector injector = createStrictMock(Injector.class); MaintenanceStateHelper maintenanceStateHelper = createMockBuilder( MaintenanceStateHelper.class).withConstructor(injector).createNiceMock(); Clusters clusters = createMock(Clusters.class); Cluster cluster = createMock(Cluster.class); Service service = createNiceMock(Service.class); final Host host = createNiceMock(Host.class); long clusterId = 1L; String hostName = "c6401.ambari.apache.org"; Alert alert = new Alert("foo-alert", null, "HDFS", null, hostName, AlertState.CRITICAL); expect(host.getMaintenanceState(clusterId)).andReturn(MaintenanceState.OFF).once(); expect(clusters.getHost(hostName)).andReturn(host).once(); expect(clusters.getClusterById(clusterId)).andReturn(cluster).once(); expect(cluster.getService("HDFS")).andReturn(service).once(); expect(service.getMaintenanceState()).andReturn(MaintenanceState.ON); injectField(maintenanceStateHelper, clusters); replay(maintenanceStateHelper, clusters, host, cluster, service); MaintenanceState state = maintenanceStateHelper.getEffectiveState(clusterId, alert); Assert.assertEquals(MaintenanceState.ON, state); verify(maintenanceStateHelper, clusters, host, cluster, service); }
public MaintenanceState getEffectiveState(ServiceComponentHost sch, Host host) throws AmbariException { Cluster cluster = clusters.getCluster(sch.getClusterName()); Service service = cluster.getService(sch.getServiceName()); if (null == host) { throw new HostNotFoundException(cluster.getClusterName(), sch.getHostName()); } return getEffectiveState(cluster.getClusterId(), service, host, sch); }
MaintenanceStateHelper { public MaintenanceState getEffectiveState(ServiceComponentHost sch, Host host) throws AmbariException { Cluster cluster = clusters.getCluster(sch.getClusterName()); Service service = cluster.getService(sch.getServiceName()); if (null == host) { throw new HostNotFoundException(cluster.getClusterName(), sch.getHostName()); } return getEffectiveState(cluster.getClusterId(), service, host, sch); } }
MaintenanceStateHelper { public MaintenanceState getEffectiveState(ServiceComponentHost sch, Host host) throws AmbariException { Cluster cluster = clusters.getCluster(sch.getClusterName()); Service service = cluster.getService(sch.getServiceName()); if (null == host) { throw new HostNotFoundException(cluster.getClusterName(), sch.getHostName()); } return getEffectiveState(cluster.getClusterId(), service, host, sch); } @Inject  MaintenanceStateHelper(Injector injector); }
MaintenanceStateHelper { public MaintenanceState getEffectiveState(ServiceComponentHost sch, Host host) throws AmbariException { Cluster cluster = clusters.getCluster(sch.getClusterName()); Service service = cluster.getService(sch.getServiceName()); if (null == host) { throw new HostNotFoundException(cluster.getClusterName(), sch.getHostName()); } return getEffectiveState(cluster.getClusterId(), service, host, sch); } @Inject  MaintenanceStateHelper(Injector injector); boolean isOperationAllowed(Cluster cluster,
      RequestOperationLevel levelObj, RequestResourceFilter reqFilter,
      String serviceName, String componentName, String hostname); boolean isOperationAllowed(Resource.Type level, Service service); boolean isOperationAllowed(Host host, long clusterId,
      Resource.Type level); MaintenanceState getEffectiveState(ServiceComponentHost sch, Host host); MaintenanceState getEffectiveState(ServiceComponentHost sch); MaintenanceState getEffectiveState(long clusterId, Alert alert); Set<Map<String, String>> getMaintenanceHostComponents(
      Clusters clusters, Cluster cluster); boolean isOperationAllowed(Resource.Type operationLevel,
      ServiceComponentHost sch); Resource.Type guessOperationLevel(RequestResourceFilter filter); Set<String> filterHostsInMaintenanceState(Set<String> candidateHosts,
      HostPredicate condition); }
MaintenanceStateHelper { public MaintenanceState getEffectiveState(ServiceComponentHost sch, Host host) throws AmbariException { Cluster cluster = clusters.getCluster(sch.getClusterName()); Service service = cluster.getService(sch.getServiceName()); if (null == host) { throw new HostNotFoundException(cluster.getClusterName(), sch.getHostName()); } return getEffectiveState(cluster.getClusterId(), service, host, sch); } @Inject  MaintenanceStateHelper(Injector injector); boolean isOperationAllowed(Cluster cluster,
      RequestOperationLevel levelObj, RequestResourceFilter reqFilter,
      String serviceName, String componentName, String hostname); boolean isOperationAllowed(Resource.Type level, Service service); boolean isOperationAllowed(Host host, long clusterId,
      Resource.Type level); MaintenanceState getEffectiveState(ServiceComponentHost sch, Host host); MaintenanceState getEffectiveState(ServiceComponentHost sch); MaintenanceState getEffectiveState(long clusterId, Alert alert); Set<Map<String, String>> getMaintenanceHostComponents(
      Clusters clusters, Cluster cluster); boolean isOperationAllowed(Resource.Type operationLevel,
      ServiceComponentHost sch); Resource.Type guessOperationLevel(RequestResourceFilter filter); Set<String> filterHostsInMaintenanceState(Set<String> candidateHosts,
      HostPredicate condition);  }