Browse Source

AMBARI-7729. Ambari throws Runtime exception for unrecognized components in DB. (aonishuk)

Andrew Onishuk 10 năm trước cách đây
mục cha
commit
183ab7a801

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java

@@ -134,7 +134,7 @@ public class ServiceComponentImpl implements ServiceComponent {
         stackId.getStackName(), stackId.getStackVersion(), service.getName(),
         getName());
     if (compInfo == null) {
-      throw new RuntimeException("Trying to create a ServiceComponent"
+      throw new AmbariException("Trying to create a ServiceComponent"
           + " not recognized in stack info"
           + ", clusterName=" + service.getCluster().getClusterName()
           + ", serviceName=" + service.getName()

+ 12 - 3
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java

@@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory;
 import com.google.gson.Gson;
 import com.google.inject.Inject;
 import com.google.inject.Injector;
+import com.google.inject.ProvisionException;
 import com.google.inject.assistedinject.Assisted;
 import com.google.inject.assistedinject.AssistedInject;
 import com.google.inject.persist.Transactional;
@@ -129,9 +130,17 @@ public class ServiceImpl implements Service {
     if (!serviceEntity.getServiceComponentDesiredStateEntities().isEmpty()) {
       for (ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity
           : serviceEntity.getServiceComponentDesiredStateEntities()) {
-        components.put(serviceComponentDesiredStateEntity.getComponentName(),
-            serviceComponentFactory.createExisting(this,
-                serviceComponentDesiredStateEntity));
+        try {
+            components.put(serviceComponentDesiredStateEntity.getComponentName(),
+                serviceComponentFactory.createExisting(this,
+                    serviceComponentDesiredStateEntity));
+          } catch(ProvisionException ex) {
+            StackId stackId = cluster.getCurrentStackVersion();
+            LOG.error(String.format("Can not get component info: stackName=%s, stackVersion=%s, serviceName=%s, componentName=%s",
+                stackId.getStackName(), stackId.getStackVersion(),
+                serviceEntity.getServiceName(),serviceComponentDesiredStateEntity.getComponentName()));
+            ex.printStackTrace();
+          }
       }
     }