You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by hi...@apache.org on 2012/10/19 00:41:09 UTC
svn commit: r1399899 - in /incubator/ambari/branches/AMBARI-666: ./
ambari-server/src/main/java/org/apache/ambari/server/controller/
ambari-server/src/main/java/org/apache/ambari/server/state/
ambari-server/src/main/java/org/apache/ambari/server/state/...
Author: hitesh
Date: Thu Oct 18 22:41:08 2012
New Revision: 1399899
URL: http://svn.apache.org/viewvc?rev=1399899&view=rev
Log:
AMBARI-886. Support filters in controller get* apis. (Contributed by hitesh)
Added:
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/JobTest.java (with props)
Removed:
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/JobImplTest.java
Modified:
incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHostFactory.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceFactory.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1399899&r1=1399898&r2=1399899&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Thu Oct 18 22:41:08 2012
@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
NEW FEATURES
+ AMBARI-886. Support filters in controller get* apis. (hitesh)
+
AMBARI-880. Implement Review Page (Step 8) for the Ambari Installer
Wizard. (Jaimin Jetly via yusaku)
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1399899&r1=1399898&r2=1399899&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java Thu Oct 18 22:41:08 2012
@@ -23,6 +23,7 @@ import org.apache.ambari.server.AmbariEx
import org.apache.ambari.server.HostNotFoundException;
import org.apache.ambari.server.Role;
import org.apache.ambari.server.RoleCommand;
+import org.apache.ambari.server.ServiceComponentHostNotFoundException;
import org.apache.ambari.server.actionmanager.ActionManager;
import org.apache.ambari.server.actionmanager.Stage;
import org.apache.ambari.server.agent.ExecutionCommand;
@@ -62,7 +63,6 @@ public class AmbariManagementControllerI
private final Injector injector;
- // FIXME does this need to be initialized via the meta data library?
private static RoleCommandOrder rco;
static {
rco = new RoleCommandOrder();
@@ -124,7 +124,8 @@ public class AmbariManagementControllerI
throws AmbariException {
if (requests.isEmpty()) {
- // TODO log warning for invalid request
+ LOG.warn("Received an empty requests set");
+ return;
}
// do all validation checks
@@ -237,7 +238,8 @@ public class AmbariManagementControllerI
Set<ServiceComponentRequest> requests) throws AmbariException {
if (requests.isEmpty()) {
- // TODO log warning for invalid request
+ LOG.warn("Received an empty requests set");
+ return;
}
// do all validation checks
@@ -374,7 +376,8 @@ public class AmbariManagementControllerI
throws AmbariException {
if (requests.isEmpty()) {
- // TODO log warning for invalid request
+ LOG.warn("Received an empty requests set");
+ return;
}
Set<String> duplicates = new HashSet<String>();
@@ -461,7 +464,8 @@ public class AmbariManagementControllerI
throws AmbariException {
if (requests.isEmpty()) {
- // TODO log warning for invalid request
+ LOG.warn("Received an empty requests set");
+ return;
}
// do all validation checks
@@ -541,6 +545,26 @@ public class AmbariManagementControllerI
Service s = cluster.getService(request.getServiceName());
ServiceComponent sc = s.getServiceComponent(
request.getComponentName());
+ Host host = clusters.getHost(request.getHostname());
+ Set<Cluster> mappedClusters =
+ clusters.getClustersForHost(host.getHostName());
+ boolean validCluster = false;
+ for (Cluster mappedCluster : mappedClusters) {
+ if (mappedCluster.getClusterName().equals(
+ request.getClusterName())) {
+ validCluster = true;
+ break;
+ }
+ }
+ if (!validCluster) {
+ // TODO fix throw correct error
+ throw new AmbariException("Invalid request as host does not belong to"
+ + " given cluster"
+ + ", clusterName=" + request.getClusterName()
+ + ", serviceName=" + request.getServiceName()
+ + ", componentName=" + request.getComponentName()
+ + ", hostname=" + request.getHostname());
+ }
try {
ServiceComponentHost sch = sc.getServiceComponentHost(
request.getHostname());
@@ -686,8 +710,18 @@ public class AmbariManagementControllerI
return response;
}
+ // FIXME validate stack version if not null
+
Map<String, Cluster> allClusters = clusters.getClusters();
for (Cluster c : allClusters.values()) {
+ if (request.getStackVersion() != null
+ && !request.getStackVersion().isEmpty()) {
+ if (!request.getStackVersion().equals(
+ c.getDesiredStackVersion().getStackVersion())) {
+ // skip non matching stack versions
+ continue;
+ }
+ }
response.add(c.convertToResponse());
}
return response;
@@ -699,7 +733,6 @@ public class AmbariManagementControllerI
if (request.getClusterName() == null
|| request.getClusterName().isEmpty()) {
// TODO fix throw error
- // or handle all possible searches for null properties
throw new AmbariException("Invalid arguments");
}
final Cluster cluster = clusters.getCluster(request.getClusterName());
@@ -712,10 +745,25 @@ public class AmbariManagementControllerI
}
// TODO support search on predicates?
- // filter based on desired state?
- Map<String, Service> allServices = cluster.getServices();
- for (Service s : allServices.values()) {
+ boolean checkDesiredState = false;
+ State desiredStateToCheck = null;
+ if (request.getDesiredState() != null
+ && !request.getDesiredState().isEmpty()) {
+ desiredStateToCheck = State.valueOf(request.getDesiredState());
+ if (!desiredStateToCheck.isValidDesiredState()) {
+ // FIXME throw correct error
+ throw new AmbariException("Invalid arguments");
+ }
+ checkDesiredState = true;
+ }
+
+ for (Service s : cluster.getServices().values()) {
+ if (checkDesiredState
+ && (desiredStateToCheck != s.getDesiredState())) {
+ // skip non matching state
+ continue;
+ }
response.add(s.convertToResponse());
}
return response;
@@ -726,28 +774,57 @@ public class AmbariManagementControllerI
public Set<ServiceComponentResponse> getComponents(
ServiceComponentRequest request) throws AmbariException {
if (request.getClusterName() == null
- || request.getClusterName().isEmpty()
- || request.getServiceName() == null
- || request.getServiceName().isEmpty()) {
+ || request.getClusterName().isEmpty()) {
// TODO fix throw error
- // or handle all possible searches for null properties
throw new AmbariException("Invalid arguments");
}
final Cluster cluster = clusters.getCluster(request.getClusterName());
- final Service s = cluster.getService(request.getServiceName());
Set<ServiceComponentResponse> response =
new HashSet<ServiceComponentResponse>();
+
if (request.getComponentName() != null) {
+ if (request.getServiceName() == null) {
+ // TODO fix throw error
+ throw new AmbariException("Invalid arguments");
+ }
+ Service s = cluster.getService(request.getServiceName());
ServiceComponent sc = s.getServiceComponent(request.getComponentName());
response.add(sc.convertToResponse());
return response;
}
- Map<String, ServiceComponent> allSvcComps = s.getServiceComponents();
- for (ServiceComponent sc : allSvcComps.values()) {
- response.add(sc.convertToResponse());
+ boolean checkDesiredState = false;
+ State desiredStateToCheck = null;
+ if (request.getDesiredState() != null
+ && !request.getDesiredState().isEmpty()) {
+ desiredStateToCheck = State.valueOf(request.getDesiredState());
+ if (!desiredStateToCheck.isValidDesiredState()) {
+ // FIXME throw correct error
+ throw new AmbariException("Invalid arguments");
+ }
+ checkDesiredState = true;
+ }
+
+ Set<Service> services = new HashSet<Service>();
+ if (request.getServiceName() != null
+ && !request.getServiceName().isEmpty()) {
+ services.add(cluster.getService(request.getServiceName()));
+ } else {
+ services.addAll(cluster.getServices().values());
+ }
+
+ for (Service s : services) {
+ // filter on request.getDesiredState()
+ for (ServiceComponent sc : s.getServiceComponents().values()) {
+ if (checkDesiredState
+ && (desiredStateToCheck != sc.getDesiredState())) {
+ // skip non matching state
+ continue;
+ }
+ response.add(sc.convertToResponse());
+ }
}
return response;
}
@@ -757,6 +834,8 @@ public class AmbariManagementControllerI
throws AmbariException {
Set<HostResponse> response = new HashSet<HostResponse>();
+ // FIXME what is the requirement for filtering on host attributes?
+
List<Host> hosts = null;
if (request.getHostname() != null) {
Host h = clusters.getHost(request.getHostname());
@@ -782,11 +861,7 @@ public class AmbariManagementControllerI
public Set<ServiceComponentHostResponse> getHostComponents(
ServiceComponentHostRequest request) throws AmbariException {
if (request.getClusterName() == null
- || request.getClusterName().isEmpty()
- || request.getServiceName() == null
- || request.getServiceName().isEmpty()
- || request.getComponentName() == null
- || request.getComponentName().isEmpty()) {
+ || request.getClusterName().isEmpty()) {
// TODO fix throw error
// or handle all possible searches for null properties
throw new AmbariException("Invalid arguments");
@@ -794,29 +869,81 @@ public class AmbariManagementControllerI
final Cluster cluster = clusters.getCluster(request.getClusterName());
- // TODO should service name be allowed to be null?
+ if (request.getComponentName() != null) {
+ if (request.getServiceName() == null) {
+ // FIXME get service name from meta data or throw exception??
+ // for now using a brute force search across all services
+ }
+ }
- final Service s = cluster.getService(request.getServiceName());
- final ServiceComponent sc = s.getServiceComponent(
- request.getComponentName());
+ Set<Service> services = new HashSet<Service>();
+ if (request.getServiceName() != null
+ && !request.getServiceName().isEmpty()) {
+ services.add(cluster.getService(request.getServiceName()));
+ } else {
+ services.addAll(cluster.getServices().values());
+ }
Set<ServiceComponentHostResponse> response =
new HashSet<ServiceComponentHostResponse>();
- if (request.getHostname() != null) {
- ServiceComponentHost sch = sc.getServiceComponentHost(
- request.getHostname());
- ServiceComponentHostResponse r = sch.convertToResponse();
- response.add(r);
- return response;
+ boolean checkDesiredState = false;
+ State desiredStateToCheck = null;
+ if (request.getDesiredState() != null
+ && !request.getDesiredState().isEmpty()) {
+ desiredStateToCheck = State.valueOf(request.getDesiredState());
+ if (!desiredStateToCheck.isValidDesiredState()) {
+ // FIXME throw correct error
+ throw new AmbariException("Invalid arguments");
+ }
+ checkDesiredState = true;
}
- Map<String, ServiceComponentHost> allSch = sc.getServiceComponentHosts();
- for (ServiceComponentHost sch : allSch.values()) {
- ServiceComponentHostResponse r = sch.convertToResponse();
- response.add(r);
- }
+ for (Service s : services) {
+ // filter on component name if provided
+ Set<ServiceComponent> components = new HashSet<ServiceComponent>();
+ // FIXME hack for now as we need to filter on name until meta data layer
+ // integration happens
+ // at that point, only a single component object should be looked at
+ components.addAll(s.getServiceComponents().values());
+ for(ServiceComponent sc : components) {
+ if (request.getComponentName() != null) {
+ if (!sc.getName().equals(request.getComponentName())) {
+ // FIXME for
+ continue;
+ }
+ }
+ // filter on hostname if provided
+ // filter on desired state if provided
+
+ if (request.getHostname() != null) {
+ try {
+ ServiceComponentHost sch = sc.getServiceComponentHost(
+ request.getHostname());
+ if (checkDesiredState
+ && (desiredStateToCheck != sch.getDesiredState())) {
+ continue;
+ }
+ ServiceComponentHostResponse r = sch.convertToResponse();
+ response.add(r);
+ } catch (ServiceComponentHostNotFoundException e) {
+ // Expected
+ // ignore and continue
+ }
+ } else {
+ for (ServiceComponentHost sch :
+ sc.getServiceComponentHosts().values()) {
+ if (checkDesiredState
+ && (desiredStateToCheck != sch.getDesiredState())) {
+ continue;
+ }
+ ServiceComponentHostResponse r = sch.convertToResponse();
+ response.add(r);
+ }
+ }
+ }
+ }
return response;
}
@@ -994,7 +1121,7 @@ public class AmbariManagementControllerI
throws AmbariException {
if (requests.isEmpty()) {
- // TODO log warning for invalid request
+ LOG.warn("Received an empty requests set");
// FIXME return val
return null;
}
@@ -1165,7 +1292,7 @@ public class AmbariManagementControllerI
Set<ServiceComponentRequest> requests) throws AmbariException {
if (requests.isEmpty()) {
- // TODO log warning for invalid request
+ LOG.warn("Received an empty requests set");
// FIXME fix return val
return null;
}
@@ -1326,10 +1453,6 @@ public class AmbariManagementControllerI
// TODO additional validation?
- // TODO order hostcomponents to determine stages
-
- // TODO lets continue hacking
-
Cluster cluster = clusters.getCluster(clusterNames.iterator().next());
return doStageCreation(cluster, null,
@@ -1341,7 +1464,8 @@ public class AmbariManagementControllerI
throws AmbariException {
if (requests.isEmpty()) {
- // TODO log warning for invalid request
+ LOG.warn("Received an empty requests set");
+ return;
}
for (HostRequest request : requests) {
@@ -1373,7 +1497,7 @@ public class AmbariManagementControllerI
Set<ServiceComponentHostRequest> requests) throws AmbariException {
if (requests.isEmpty()) {
- // TODO log warning for invalid request
+ LOG.warn("Received an empty requests set");
// FIXME fix return val
return null;
}
@@ -1528,9 +1652,6 @@ public class AmbariManagementControllerI
// TODO additional validation?
- // TODO order hostcomponents to determine stages
-
- // TODO lets continue hacking
Cluster cluster = clusters.getCluster(clusterNames.iterator().next());
return doStageCreation(cluster, null,
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java?rev=1399899&r1=1399898&r2=1399899&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java Thu Oct 18 22:41:08 2012
@@ -66,5 +66,6 @@ public interface Service {
void refresh();
- ServiceComponent addServiceComponent(String serviceComponentName) throws AmbariException;
+ ServiceComponent addServiceComponent(String serviceComponentName)
+ throws AmbariException;
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java?rev=1399899&r1=1399898&r2=1399899&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java Thu Oct 18 22:41:08 2012
@@ -32,7 +32,6 @@ public interface ServiceComponent {
public long getClusterId();
- // TODO
public String getClusterName();
public State getDesiredState();
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHostFactory.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHostFactory.java?rev=1399899&r1=1399898&r2=1399899&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHostFactory.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHostFactory.java Thu Oct 18 22:41:08 2012
@@ -1,6 +1,23 @@
+/**
+ * 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.state;
-import com.google.inject.assistedinject.Assisted;
import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceFactory.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceFactory.java?rev=1399899&r1=1399898&r2=1399899&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceFactory.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceFactory.java Thu Oct 18 22:41:08 2012
@@ -1,3 +1,21 @@
+/**
+ * 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.state;
import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java?rev=1399899&r1=1399898&r2=1399899&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java Thu Oct 18 22:41:08 2012
@@ -21,7 +21,6 @@ package org.apache.ambari.server.state.c
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -40,14 +39,11 @@ import org.apache.ambari.server.controll
import org.apache.ambari.server.orm.dao.ClusterDAO;
import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
import org.apache.ambari.server.orm.entities.ClusterEntity;
-import org.apache.ambari.server.ServiceComponentHostNotFoundException;
import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
import org.apache.ambari.server.state.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.persistence.EntityManager;
-
public class ClusterImpl implements Cluster {
private static final Logger LOG =
@@ -82,7 +78,6 @@ public class ClusterImpl implements Clus
private Lock writeLock = readWriteLock.writeLock();
private final Injector injector;
-
private ClusterEntity clusterEntity;
@Inject
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java?rev=1399899&r1=1399898&r2=1399899&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java Thu Oct 18 22:41:08 2012
@@ -33,6 +33,7 @@ import org.apache.ambari.server.actionma
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Service;
import org.apache.ambari.server.state.ServiceComponent;
import org.apache.ambari.server.state.ServiceComponentHost;
import org.apache.ambari.server.state.State;
@@ -70,13 +71,6 @@ public class AmbariManagementControllerT
private void createCluster(String clusterName) throws AmbariException {
ClusterRequest r = new ClusterRequest(null, clusterName, "1.0.0", null);
controller.createCluster(r);
-
- try {
- controller.createCluster(r);
- fail("Duplicate cluster creation should fail");
- } catch (Exception e) {
- // Expected
- }
}
private void createService(String clusterName,
@@ -87,28 +81,9 @@ public class AmbariManagementControllerT
}
ServiceRequest r1 = new ServiceRequest(clusterName, serviceName, null,
dStateStr);
- ServiceRequest r2 = new ServiceRequest(clusterName, serviceName, null,
- dStateStr);
Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
requests.add(r1);
- requests.add(r2);
- try {
- controller.createServices(requests);
- fail("Expected error for duplicates");
- } catch (Exception e) {
- // Expected
- }
-
- requests.clear();
- requests.add(r1);
controller.createServices(requests);
-
- try {
- controller.createServices(requests);
- fail("Duplicate Service creation should fail");
- } catch (Exception e) {
- // Expected
- }
}
private void createServiceComponent(String clusterName,
@@ -156,7 +131,7 @@ public class AmbariManagementControllerT
}
@Test
- public void testCreateCluster() throws AmbariException {
+ public void testCreateClusterSimple() throws AmbariException {
String clusterName = "foo1";
createCluster(clusterName);
Set<ClusterResponse> r =
@@ -164,10 +139,79 @@ public class AmbariManagementControllerT
Assert.assertEquals(1, r.size());
ClusterResponse c = r.iterator().next();
Assert.assertEquals(clusterName, c.getClusterName());
+
+ try {
+ createCluster(clusterName);
+ fail("Duplicate cluster creation should fail");
+ } catch (AmbariException e) {
+ // Expected
+ }
+ }
+
+ @Test
+ public void testCreateClusterWithInvalidStack() {
+ // TODO implement test after meta data integration
+ }
+
+ @Test
+ public void testCreateClusterWithHostMapping() {
+ // TODO write test
+ // check for invalid hosts
+ }
+
+ @Test
+ public void testCreateClusterWithDesiredClusterConfigs() {
+ // TODO implement after configs integration
+ }
+
+ @Test
+ public void testCreateClusterWithInvalidRequest() {
+ // TODO write test
}
@Test
- public void testCreateService() throws AmbariException {
+ public void testCreateClusterWithExistingServices() {
+ // TODO write test
+ }
+
+ @Test
+ public void testCreateServicesSimple() throws AmbariException {
+ String clusterName = "foo1";
+ createCluster(clusterName);
+ String serviceName = "HDFS";
+ createService(clusterName, serviceName, State.INIT);
+ Service s =
+ clusters.getCluster(clusterName).getService(serviceName);
+ Assert.assertNotNull(s);
+ Assert.assertEquals(serviceName, s.getName());
+ Assert.assertEquals(clusterName, s.getCluster().getClusterName());
+
+ ServiceRequest req = new ServiceRequest(clusterName, serviceName,
+ null, null);
+
+ Set<ServiceResponse> r =
+ controller.getServices(req);
+ Assert.assertEquals(1, r.size());
+ ServiceResponse resp = r.iterator().next();
+ Assert.assertEquals(serviceName, resp.getServiceName());
+ Assert.assertEquals(clusterName, resp.getClusterName());
+ Assert.assertEquals(State.INIT.toString(),
+ resp.getDesiredState());
+ Assert.assertEquals("1.0.0", resp.getDesiredStackVersion());
+
+ // TODO test resp.getConfigVersions()
+ }
+
+ @Test
+ public void testCreateServicesWithInvalidRequest() {
+ // TODO write test
+ // invalid request
+ // dups in requests
+ // multi cluster updates
+ }
+
+ @Test
+ public void testCreateServiceWithInvalidInfo() throws AmbariException {
String clusterName = "foo1";
createCluster(clusterName);
String serviceName = "HDFS";
@@ -205,7 +249,10 @@ public class AmbariManagementControllerT
Assert.assertEquals("1.0.0", svc.getDesiredStackVersion());
Assert.assertEquals(State.INIT.toString(), svc.getDesiredState());
}
+ }
+ @Test
+ public void testCreateServicesMultiple() {
}
@@ -336,9 +383,10 @@ public class AmbariManagementControllerT
controller.getHostComponents(r);
Assert.assertEquals(2, response.size());
- // TODO fix
}
+
+
@Test
public void testCreateHost() throws AmbariException {
List<String> clusterNames = null;
@@ -499,4 +547,5 @@ public class AmbariManagementControllerT
}
+
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java?rev=1399899&r1=1399898&r2=1399899&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java Thu Oct 18 22:41:08 2012
@@ -188,6 +188,7 @@ public class ServiceComponentTest {
addHostToCluster("h1", service.getCluster().getClusterName());
addHostToCluster("h2", service.getCluster().getClusterName());
+ addHostToCluster("h3", service.getCluster().getClusterName());
ServiceComponentHost sch1 =
serviceComponentHostFactory.createNew(sc, "h1", false);
@@ -218,6 +219,16 @@ public class ServiceComponentTest {
sch1.persist();
sch2.persist();
+ ServiceComponentHost schCheck = sc.getServiceComponentHost("h2");
+ Assert.assertNotNull(schCheck);
+ Assert.assertEquals("h2", schCheck.getHostName());
+
+ ServiceComponentHost sch3 =
+ serviceComponentHostFactory.createNew(sc, "h3", false);
+ sc.addServiceComponentHost(sch3);
+ sch3.persist();
+ Assert.assertNotNull(sc.getServiceComponentHost("h3"));
+
sch1.setDesiredStackVersion(new StackVersion("1.1.0"));
sch1.setState(State.STARTING);
sch1.setStackVersion(new StackVersion("1.0.0"));
@@ -288,6 +299,7 @@ public class ServiceComponentTest {
// TODO test debug dump
StringBuilder sb = new StringBuilder();
sc.debugDump(sb);
+ Assert.assertFalse(sb.toString().isEmpty());
}
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java?rev=1399899&r1=1399898&r2=1399899&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java Thu Oct 18 22:41:08 2012
@@ -26,6 +26,7 @@ import java.util.Map;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
+
import junit.framework.Assert;
import org.apache.ambari.server.AmbariException;
@@ -149,14 +150,26 @@ public class ServiceTest {
sc2.persist();
sc3.persist();
+ ServiceComponent sc4 = s.addServiceComponent("sc4");
+ Assert.assertNotNull(s.getServiceComponent(sc4.getName()));
+ Assert.assertEquals(State.INIT,
+ s.getServiceComponent("sc4").getDesiredState());
+ sc4.persist();
+
+ Assert.assertEquals(4, s.getServiceComponents().size());
+
Assert.assertNotNull(s.getServiceComponent(sc3.getName()));
- Assert.assertEquals(3, s.getServiceComponents().size());
Assert.assertEquals(sc3.getName(),
s.getServiceComponent(sc3.getName()).getName());
Assert.assertEquals(s.getName(),
s.getServiceComponent(sc3.getName()).getServiceName());
Assert.assertEquals(cluster.getClusterName(),
s.getServiceComponent(sc3.getName()).getClusterName());
+
+ sc4.setDesiredState(State.INSTALLING);
+ Assert.assertEquals(State.INSTALLING,
+ s.getServiceComponent("sc4").getDesiredState());
+
}
@Test
@@ -165,8 +178,6 @@ public class ServiceTest {
/*
public Map<String, Config> getDesiredConfigs();
public void updateDesiredConfigs(Map<String, Config> configs);
- public Map<String, Config> getConfigs();
- public void updateConfigs(Map<String, Config> configs);
*/
}
@@ -200,6 +211,11 @@ public class ServiceTest {
r.getDesiredState());
// FIXME add checks for configs
+ StringBuilder sb = new StringBuilder();
+ s.debugDump(sb);
+ // TODO better checks?
+ Assert.assertFalse(sb.toString().isEmpty());
+
}
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java?rev=1399899&r1=1399898&r2=1399899&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java Thu Oct 18 22:41:08 2012
@@ -20,6 +20,7 @@ package org.apache.ambari.server.state.c
import static org.junit.Assert.fail;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -31,6 +32,7 @@ import junit.framework.Assert;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.ClusterNotFoundException;
+import org.apache.ambari.server.HostNotFoundException;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.state.Cluster;
@@ -107,6 +109,17 @@ public class ClustersTest {
Assert.assertNotNull(verifyClusters.get(c1));
Assert.assertNotNull(verifyClusters.get(c2));
+ Cluster c = clusters.getCluster(c1);
+ c.setClusterName("foobar");
+ long cId = c.getClusterId();
+
+ Cluster changed = clusters.getCluster("foobar");
+ Assert.assertNotNull(changed);
+ Assert.assertEquals(cId, changed.getClusterId());
+
+ Assert.assertEquals("foobar",
+ clusters.getClusterById(cId).getClusterName());
+
}
@@ -135,6 +148,16 @@ public class ClustersTest {
Assert.assertNotNull(clusters.getHost(h2));
Assert.assertNotNull(clusters.getHost(h3));
+ Host h = clusters.getHost(h2);
+ Assert.assertNotNull(h);
+
+ try {
+ clusters.getHost("foo");
+ fail("Expected error for unknown host");
+ } catch (HostNotFoundException e) {
+ // Expected
+ }
+
}
@Test
@@ -168,14 +191,18 @@ public class ClustersTest {
clusters.addHost(h3);
Assert.assertNotNull(clusters.getHost(h1));
+ Set<Cluster> c = clusters.getClustersForHost(h3);
+ Assert.assertEquals(0, c.size());
+
clusters.mapHostToCluster(h1, c1);
- clusters.mapHostToCluster(h1, c2);
clusters.mapHostToCluster(h2, c1);
- clusters.mapHostToCluster(h2, c2);
- clusters.mapHostToCluster(h1, c2);
+ clusters.mapHostToCluster(h1, c1);
- Set<Cluster> c = clusters.getClustersForHost(h3);
- Assert.assertEquals(0, c.size());
+ Set<String> hostnames = new HashSet<String>();
+ hostnames.add(h1);
+ hostnames.add(h2);
+
+ clusters.mapHostsToCluster(hostnames, c2);
c = clusters.getClustersForHost(h1);
Assert.assertEquals(2, c.size());
@@ -183,13 +210,34 @@ public class ClustersTest {
c = clusters.getClustersForHost(h2);
Assert.assertEquals(2, c.size());
- // TODO write test for mapHostsToCluster
+ // TODO write test for getHostsForCluster
+ Map<String, Host> hostsForC1 = clusters.getHostsForCluster(c1);
+ Assert.assertEquals(2, hostsForC1.size());
+ Assert.assertTrue(hostsForC1.containsKey(h1));
+ Assert.assertTrue(hostsForC1.containsKey(h2));
+ Assert.assertNotNull(hostsForC1.get(h1));
+ Assert.assertNotNull(hostsForC1.get(h2));
}
@Test
- public void testDebugDump() {
- // TODO write unit test
+ public void testDebugDump() throws AmbariException {
+ String c1 = "c1";
+ String c2 = "c2";
+ String h1 = "h1";
+ String h2 = "h2";
+ String h3 = "h3";
+ clusters.addCluster(c1);
+ clusters.addCluster(c2);
+ clusters.addHost(h1);
+ clusters.addHost(h2);
+ clusters.addHost(h3);
+ clusters.mapHostToCluster(h1, c1);
+ clusters.mapHostToCluster(h2, c1);
+
+ StringBuilder sb = new StringBuilder();
+ clusters.debugDump(sb);
+ // TODO verify dump output?
}
}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/JobTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/JobTest.java?rev=1399899&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/JobTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/JobTest.java Thu Oct 18 22:41:08 2012
@@ -0,0 +1,153 @@
+/**
+ * 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.state.job;
+
+import org.apache.ambari.server.state.job.Job;
+import org.apache.ambari.server.state.job.JobCompletedEvent;
+import org.apache.ambari.server.state.job.JobEvent;
+import org.apache.ambari.server.state.job.JobFailedEvent;
+import org.apache.ambari.server.state.job.JobId;
+import org.apache.ambari.server.state.job.JobImpl;
+import org.apache.ambari.server.state.job.JobProgressUpdateEvent;
+import org.apache.ambari.server.state.job.JobState;
+import org.apache.ambari.server.state.job.JobType;
+import org.apache.ambari.server.state.job.NewJobEvent;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JobTest {
+
+ private Job createNewJob(long id, String jobName, long startTime) {
+ JobId jId = new JobId(id, new JobType(jobName));
+ Job job = new JobImpl(jId, startTime);
+ return job;
+ }
+
+ private Job getRunningJob(long id, String jobName, long startTime)
+ throws Exception {
+ Job job = createNewJob(id, jobName, startTime);
+ verifyProgressUpdate(job, ++startTime);
+ return job;
+ }
+
+ private Job getCompletedJob(long id, String jobName, long startTime,
+ boolean failedJob) throws Exception {
+ Job job = getRunningJob(1, "JobNameFoo", startTime);
+ completeJob(job, failedJob, ++startTime);
+ return job;
+ }
+
+ private void verifyNewJob(Job job, long startTime) {
+ Assert.assertEquals(JobState.INIT, job.getState());
+ Assert.assertEquals(startTime, job.getStartTime());
+ }
+
+
+ @Test
+ public void testNewJob() {
+ long currentTime = System.currentTimeMillis();
+ Job job = createNewJob(1, "JobNameFoo", currentTime);
+ verifyNewJob(job, currentTime);
+ }
+
+ private void verifyProgressUpdate(Job job, long updateTime)
+ throws Exception {
+ JobProgressUpdateEvent e = new JobProgressUpdateEvent(job.getId(),
+ updateTime);
+ job.handleEvent(e);
+ Assert.assertEquals(JobState.IN_PROGRESS, job.getState());
+ Assert.assertEquals(updateTime, job.getLastUpdateTime());
+ }
+
+
+ @Test
+ public void testJobProgressUpdates() throws Exception {
+ long currentTime = 1;
+ Job job = createNewJob(1, "JobNameFoo", currentTime);
+ verifyNewJob(job, currentTime);
+
+ verifyProgressUpdate(job, ++currentTime);
+ verifyProgressUpdate(job, ++currentTime);
+ verifyProgressUpdate(job, ++currentTime);
+
+ }
+
+ private void completeJob(Job job, boolean failJob, long endTime)
+ throws Exception {
+ JobEvent e = null;
+ JobState endState = null;
+ if (failJob) {
+ e = new JobFailedEvent(job.getId(), endTime);
+ endState = JobState.FAILED;
+ } else {
+ e = new JobCompletedEvent(job.getId(), endTime);
+ endState = JobState.COMPLETED;
+ }
+ job.handleEvent(e);
+ Assert.assertEquals(endState, job.getState());
+ Assert.assertEquals(endTime, job.getLastUpdateTime());
+ Assert.assertEquals(endTime, job.getCompletionTime());
+ }
+
+
+ @Test
+ public void testJobSuccessfulCompletion() throws Exception {
+ long currentTime = 1;
+ Job job = getRunningJob(1, "JobNameFoo", currentTime);
+ completeJob(job, false, ++currentTime);
+ }
+
+ @Test
+ public void testJobFailedCompletion() throws Exception {
+ long currentTime = 1;
+ Job job = getRunningJob(1, "JobNameFoo", currentTime);
+ completeJob(job, true, ++currentTime);
+ }
+
+ @Test
+ public void completeNewJob() throws Exception {
+ long currentTime = 1;
+ Job job = createNewJob(1, "JobNameFoo", currentTime);
+ verifyNewJob(job, currentTime);
+ completeJob(job, false, ++currentTime);
+ }
+
+ @Test
+ public void failNewJob() throws Exception {
+ long currentTime = 1;
+ Job job = createNewJob(1, "JobNameFoo", currentTime);
+ verifyNewJob(job, currentTime);
+ completeJob(job, true, ++currentTime);
+ }
+
+ @Test
+ public void reInitCompletedJob() throws Exception {
+ Job job = getCompletedJob(1, "JobNameFoo", 1, false);
+ JobId jId = new JobId(2, new JobType("JobNameFoo"));
+ NewJobEvent e = new NewJobEvent(jId, 100);
+ job.handleEvent(e);
+ Assert.assertEquals(JobState.INIT, job.getState());
+ Assert.assertEquals(100, job.getStartTime());
+ Assert.assertEquals(-1, job.getLastUpdateTime());
+ Assert.assertEquals(-1, job.getCompletionTime());
+ Assert.assertEquals(2, job.getId().jobId);
+ }
+
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/JobTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java?rev=1399899&r1=1399898&r2=1399899&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java Thu Oct 18 22:41:08 2012
@@ -18,14 +18,22 @@
package org.apache.ambari.server.state.svccomphost;
+import java.util.List;
+import java.util.Map;
+
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
+import com.google.inject.persist.Transactional;
+
import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.controller.ServiceComponentHostResponse;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.state.*;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.job.Job;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostImpl;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostInstallEvent;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpFailedEvent;
@@ -69,7 +77,7 @@ public class ServiceComponentHostTest {
injector.getInstance(PersistService.class).stop();
}
- private ServiceComponentHost createNewServiceComponentHost(long clusterId,
+ private ServiceComponentHost createNewServiceComponentHost(
String svc,
String svcComponent,
String hostName, boolean isClient) throws AmbariException{
@@ -80,13 +88,24 @@ public class ServiceComponentHostTest {
sc, hostName, isClient);
Assert.assertEquals(State.INIT,
impl.getState());
+ Assert.assertEquals(State.INIT,
+ impl.getDesiredState());
+ Assert.assertEquals("C1", impl.getClusterName());
+ Assert.assertEquals(c.getClusterId(), impl.getClusterId());
+ Assert.assertEquals(s.getName(), impl.getServiceName());
+ Assert.assertEquals(sc.getName(), impl.getServiceComponentName());
+ Assert.assertEquals(hostName, impl.getHostName());
+ Assert.assertTrue(
+ impl.getDesiredStackVersion().getStackVersion().isEmpty());
+ Assert.assertTrue(impl.getStackVersion().getStackVersion().isEmpty());
+
return impl;
}
@Test
public void testNewServiceComponentHostImpl() throws AmbariException{
- createNewServiceComponentHost(1, "svc", "svcComp", "h1", false);
- createNewServiceComponentHost(1, "svc", "svcComp", "h1", true);
+ createNewServiceComponentHost("svc", "svcComp", "h1", false);
+ createNewServiceComponentHost("svc", "svcComp", "h1", true);
}
private ServiceComponentHostEvent createEvent(ServiceComponentHostImpl impl,
@@ -258,8 +277,8 @@ public class ServiceComponentHostTest {
@Test
public void testClientStateFlow() throws Exception {
- ServiceComponentHostImpl impl = (ServiceComponentHostImpl) createNewServiceComponentHost(1, "svc",
- "svcComp", "h1", true);
+ ServiceComponentHostImpl impl = (ServiceComponentHostImpl)
+ createNewServiceComponentHost("svc", "svcComp", "h1", true);
runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
State.INIT,
@@ -296,8 +315,8 @@ public class ServiceComponentHostTest {
@Test
public void testDaemonStateFlow() throws Exception {
- ServiceComponentHostImpl impl = (ServiceComponentHostImpl) createNewServiceComponentHost(1, "svc",
- "svcComp", "h1", false);
+ ServiceComponentHostImpl impl = (ServiceComponentHostImpl)
+ createNewServiceComponentHost("svc", "svcComp", "h1", false);
runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
State.INIT,
@@ -330,4 +349,62 @@ public class ServiceComponentHostTest {
State.INIT);
}
+ @Test
+ public void testJobHandling() {
+ // TODO fix once jobs are handled
+ }
+
+
+ @Test
+ public void testGetAndSetConfigs() {
+ // FIXME config handling
+ /*
+ public Map<String, Config> getDesiredConfigs();
+ public void updateDesiredConfigs(Map<String, Config> configs);
+ public Map<String, Config> getConfigs();
+ public void updateConfigs(Map<String, Config> configs);
+ */
+ }
+
+ @Test
+ public void testGetAndSetBasicInfo() throws AmbariException {
+ ServiceComponentHost sch =
+ createNewServiceComponentHost("svc", "svcComp", "h1", false);
+ sch.setDesiredState(State.INSTALLED);
+ sch.setState(State.INSTALLING);
+ sch.setStackVersion(new StackVersion("1.0.0"));
+ sch.setDesiredStackVersion(new StackVersion("1.1.0"));
+
+ Assert.assertEquals(State.INSTALLING, sch.getState());
+ Assert.assertEquals(State.INSTALLED, sch.getDesiredState());
+ Assert.assertEquals("1.0.0",
+ sch.getStackVersion().getStackVersion());
+ Assert.assertEquals("1.1.0",
+ sch.getDesiredStackVersion().getStackVersion());
+ }
+
+ @Test
+ public void testConvertToResponse() throws AmbariException {
+ ServiceComponentHost sch =
+ createNewServiceComponentHost("svc", "svcComp", "h1", false);
+ sch.setDesiredState(State.INSTALLED);
+ sch.setState(State.INSTALLING);
+ sch.setStackVersion(new StackVersion("1.0.0"));
+ ServiceComponentHostResponse r =
+ sch.convertToResponse();
+ Assert.assertEquals("svc", r.getServiceName());
+ Assert.assertEquals("svcComp", r.getComponentName());
+ Assert.assertEquals("h1", r.getHostname());
+ Assert.assertEquals("C1", r.getClusterName());
+ Assert.assertEquals(State.INSTALLED.toString(), r.getDesiredState());
+ Assert.assertEquals(State.INSTALLING.toString(), r.getLiveState());
+ Assert.assertEquals("1.0.0", r.getStackVersion());
+
+ // TODO check configs
+
+ StringBuilder sb = new StringBuilder();
+ sch.debugDump(sb);
+ Assert.assertFalse(sb.toString().isEmpty());
+ }
+
}