Ejemplo n.º 1
0
  private ServiceModule createServiceModule(
      ServiceInfo serviceInfo, Collection<ConfigurationModule> configurations) {
    String serviceName = serviceInfo.getName();

    if (serviceInfo.getName() == null) {
      serviceInfo.setName("service1");
    }

    return createServiceModule(serviceInfo, configurations, createStackContext(serviceName, true));
  }
Ejemplo n.º 2
0
  private ServiceModule createServiceModule(ServiceInfo serviceInfo) {
    String configType = "type1";

    if (serviceInfo.getName() == null) {
      serviceInfo.setName("service1");
    }

    StackContext context = createStackContext(serviceInfo.getName(), true);
    // no config props
    ConfigurationInfo configInfo =
        createConfigurationInfo(
            Collections.<PropertyInfo>emptyList(), Collections.<String, String>emptyMap());

    ConfigurationModule module = createConfigurationModule(configType, configInfo);
    ConfigurationDirectory configDirectory =
        createConfigurationDirectory(Collections.singletonList(module));
    ServiceDirectory serviceDirectory =
        createServiceDirectory(serviceInfo.getConfigDir(), configDirectory);

    return createServiceModule(context, serviceInfo, serviceDirectory);
  }
Ejemplo n.º 3
0
  @Test
  public void testServiceCheckRegistered() throws Exception {
    ServiceInfo info = new ServiceInfo();
    info.setName("service1");
    info.setCommandScript(createNiceMock(CommandScriptDefinition.class));

    StackContext context = createStackContext(info.getName(), true);
    ServiceModule service =
        createServiceModule(info, Collections.<ConfigurationModule>emptySet(), context);
    service.finalizeModule();

    verify(context);
  }
Ejemplo n.º 4
0
  /**
   * Constructor.
   *
   * @param stackContext stack context which provides module access to external functionality
   * @param serviceInfo associated service info
   * @param serviceDirectory used for all IO interaction with service directory in stack definition
   * @param isCommonService flag to mark a service as a common service
   */
  public ServiceModule(
      StackContext stackContext,
      ServiceInfo serviceInfo,
      ServiceDirectory serviceDirectory,
      boolean isCommonService) {
    this.serviceInfo = serviceInfo;
    this.stackContext = stackContext;
    this.serviceDirectory = serviceDirectory;
    this.isCommonService = isCommonService;

    serviceInfo.setMetricsFile(serviceDirectory.getMetricsFile(serviceInfo.getName()));
    serviceInfo.setAlertsFile(serviceDirectory.getAlertsFile());
    serviceInfo.setKerberosDescriptorFile(serviceDirectory.getKerberosDescriptorFile());
    serviceInfo.setWidgetsDescriptorFile(
        serviceDirectory.getWidgetsDescriptorFile(serviceInfo.getName()));
    serviceInfo.setSchemaVersion(AmbariMetaInfo.SCHEMA_VERSION_2);
    serviceInfo.setServicePackageFolder(serviceDirectory.getPackageDir());

    populateComponentModules();
    populateConfigurationModules();
    populateThemeModules();

    validateServiceInfo();
  }
Ejemplo n.º 5
0
  private ServiceModule createServiceModule(
      ServiceInfo serviceInfo,
      Collection<ConfigurationModule> configurations,
      StackContext context) {

    if (serviceInfo.getName() == null) {
      serviceInfo.setName("service1");
    }

    ConfigurationDirectory configDirectory = createConfigurationDirectory(configurations);
    ServiceDirectory serviceDirectory =
        createServiceDirectory(serviceInfo.getConfigDir(), configDirectory);

    return createServiceModule(context, serviceInfo, serviceDirectory);
  }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
0
 @Override
 public String getId() {
   return serviceInfo.getName();
 }