http://git-wip-us.apache.org/repos/asf/ambari/blob/ba2b9700/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java new file mode 100644 index 0000000..3739516 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java @@ -0,0 +1,96 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.controller.utilities.state; + +import org.apache.ambari.server.AmbariException; +import org.apache.ambari.server.ObjectNotFoundException; +import org.apache.ambari.server.StaticallyInject; +import org.apache.ambari.server.api.services.AmbariMetaInfo; +import org.apache.ambari.server.controller.ServiceComponentHostRequest; +import org.apache.ambari.server.controller.ServiceComponentHostResponse; +import org.apache.ambari.server.state.Cluster; +import org.apache.ambari.server.state.ComponentInfo; +import org.apache.ambari.server.state.StackId; +import org.apache.ambari.server.state.State; + +import java.util.Collections; +import java.util.Set; + +/** + * Calculator of Oozie service state. + */ +@StaticallyInject +public final class OozieServiceCalculatedState extends DefaultServiceCalculatedState + implements ServiceCalculatedState { + + @Override + public State getState(String clusterName, String serviceName) { + try { + Cluster cluster = getCluster(clusterName); + if (cluster != null && managementControllerProvider != null) { + AmbariMetaInfo ambariMetaInfo = managementControllerProvider.get().getAmbariMetaInfo(); + StackId stackId = cluster.getDesiredStackVersion(); + + ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, + serviceName, null, null, null); + + Set<ServiceComponentHostResponse> hostComponentResponses = + managementControllerProvider.get().getHostComponents(Collections.singleton(request)); + + int oozieServerActiveCount = 0; + State nonStartedState = null; + + for (ServiceComponentHostResponse hostComponentResponse : hostComponentResponses ) { + try { + ComponentInfo componentInfo = ambariMetaInfo.getComponent(stackId.getStackName(), + stackId.getStackVersion(), hostComponentResponse.getServiceName(), + hostComponentResponse.getComponentName()); + + if (componentInfo.isMaster()) { + State state = getHostComponentState(hostComponentResponse); + + switch (state) { + case STARTED: + case DISABLED: + String componentName = hostComponentResponse.getComponentName(); + if (componentName.equals("OOZIE_SERVER")) { + ++oozieServerActiveCount; + } + break; + default: + nonStartedState = state; + } + } + } catch (ObjectNotFoundException e) { + // component doesn't exist, nothing to do + } + } + + // should have state INSTALLED when there is no active OOZIE_SERVER + if (oozieServerActiveCount > 0) { + return State.STARTED; + } + return nonStartedState == null ? State.INSTALLED : nonStartedState; + } + } catch (AmbariException e) { + LOG.error("Can't determine service state.", e); + } + return State.UNKNOWN; + } +}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ba2b9700/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/ServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/ServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/ServiceCalculatedState.java new file mode 100644 index 0000000..6cf3d40 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/ServiceCalculatedState.java @@ -0,0 +1,28 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.controller.utilities.state; + +import org.apache.ambari.server.state.State; + +/** + * Interface to allow for different state calculations for different services. + */ +public interface ServiceCalculatedState { + State getState(String clusterName, String serviceName); +} http://git-wip-us.apache.org/repos/asf/ambari/blob/ba2b9700/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java new file mode 100644 index 0000000..ed401ab --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java @@ -0,0 +1,102 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.controller.utilities.state; + +import org.apache.ambari.server.AmbariException; +import org.apache.ambari.server.ObjectNotFoundException; +import org.apache.ambari.server.StaticallyInject; +import org.apache.ambari.server.api.services.AmbariMetaInfo; +import org.apache.ambari.server.controller.ServiceComponentHostRequest; +import org.apache.ambari.server.controller.ServiceComponentHostResponse; +import org.apache.ambari.server.state.Cluster; +import org.apache.ambari.server.state.ComponentInfo; +import org.apache.ambari.server.state.StackId; +import org.apache.ambari.server.state.State; + +import java.util.Collections; +import java.util.Set; + +/** + * Calculator of YARN service state. + */ +@StaticallyInject +public final class YARNServiceCalculatedState extends DefaultServiceCalculatedState + implements ServiceCalculatedState { + + @Override + public State getState(String clusterName, String serviceName) { + try { + Cluster cluster = getCluster(clusterName); + if (cluster != null && managementControllerProvider != null) { + AmbariMetaInfo ambariMetaInfo = managementControllerProvider.get().getAmbariMetaInfo(); + StackId stackId = cluster.getDesiredStackVersion(); + + ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, + serviceName, null, null, null); + + Set<ServiceComponentHostResponse> hostComponentResponses = + managementControllerProvider.get().getHostComponents(Collections.singleton(request)); + + int resourceManagerActiveCount = 0; + boolean isAppTimeLineServerActive = false; + State nonStartedState = null; + + for (ServiceComponentHostResponse hostComponentResponse : hostComponentResponses ) { + try { + ComponentInfo componentInfo = ambariMetaInfo.getComponent(stackId.getStackName(), + stackId.getStackVersion(), hostComponentResponse.getServiceName(), + hostComponentResponse.getComponentName()); + + if (componentInfo.isMaster()) { + String componentName = hostComponentResponse.getComponentName(); + + State state = getHostComponentState(hostComponentResponse); + + switch (state) { + case STARTED: + case DISABLED: + if (componentName.equals("RESOURCEMANAGER")) { + ++resourceManagerActiveCount; + } else if (componentName.equals("APP_TIMELINE_SERVER")) { + isAppTimeLineServerActive = true; + } + break; + default: + nonStartedState = state; + } + } + } catch (ObjectNotFoundException e) { + // component doesn't exist, nothing to do + } + } + + if ( nonStartedState == null || // all started + (isAppTimeLineServerActive && + resourceManagerActiveCount > 0)) { // at least one active resource manager + return State.STARTED; + } + return nonStartedState; + } + } catch (AmbariException e) { + LOG.error("Can't determine service state.", e); + } + return State.UNKNOWN; + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/ba2b9700/ambari-server/src/test/java/org/apache/ambari/server/api/services/ComponentServiceTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/ComponentServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/ComponentServiceTest.java index 504e7ec..dc57a5b 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/ComponentServiceTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/ComponentServiceTest.java @@ -59,7 +59,7 @@ public class ComponentServiceTest extends BaseServiceTest { args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "componentName"}; listInvocations.add(new ServiceTestInvocation(Request.Type.POST, service, m, args, "body")); - //createComponents + //createComponentsAndHosts service = new TestComponentService("clusterName", "serviceName", null); m = service.getClass().getMethod("createComponents", String.class, HttpHeaders.class, UriInfo.class); args = new Object[] {"body", getHttpHeaders(), getUriInfo()};