Exemplo n.º 1
0
 /**
  * Resolve common service
  *
  * @param allStacks all stack modules
  * @param commonServices common service modules
  * @throws AmbariException
  */
 public void resolveCommonService(
     Map<String, StackModule> allStacks, Map<String, ServiceModule> commonServices)
     throws AmbariException {
   if (!isCommonService) {
     throw new AmbariException("Not a common service");
   }
   moduleState = ModuleState.VISITED;
   String parentString = serviceInfo.getParent();
   if (parentString != null) {
     String[] parentToks = parentString.split(StackManager.PATH_DELIMITER);
     if (parentToks.length != 3) {
       throw new AmbariException(
           "The common service '"
               + serviceInfo.getName()
               + serviceInfo.getVersion()
               + "' extends an invalid parent: '"
               + parentString
               + "'");
     }
     if (parentToks[0].equalsIgnoreCase(StackManager.COMMON_SERVICES)) {
       String baseServiceKey = parentToks[1] + StackManager.PATH_DELIMITER + parentToks[2];
       ServiceModule baseService = commonServices.get(baseServiceKey);
       ModuleState baseModuleState = baseService.getModuleState();
       if (baseModuleState == ModuleState.INIT) {
         baseService.resolveCommonService(allStacks, commonServices);
       } else if (baseModuleState == ModuleState.VISITED) {
         // todo: provide more information to user about cycle
         throw new AmbariException("Cycle detected while parsing common service");
       }
       resolve(baseService, allStacks, commonServices);
     } else {
       throw new AmbariException("Common service cannot inherit from a non common service");
     }
   }
   moduleState = ModuleState.RESOLVED;
 }