Ejemplo n.º 1
0
  /** Parse and populate child configuration modules. */
  private void populateConfigurationModules() {
    ConfigurationDirectory configDirectory =
        serviceDirectory.getConfigurationDirectory(serviceInfo.getConfigDir());

    if (configDirectory != null) {
      for (ConfigurationModule config : configDirectory.getConfigurationModules()) {
        ConfigurationInfo info = config.getModuleInfo();
        if (isValid()) {
          setValid(config.isValid() && info.isValid());
          if (!isValid()) {
            setErrors(config.getErrors());
            setErrors(info.getErrors());
          }
        }
        serviceInfo.getProperties().addAll(info.getProperties());
        serviceInfo.setTypeAttributes(config.getConfigType(), info.getAttributes());
        configurationModules.put(config.getConfigType(), config);
      }

      for (String excludedType : serviceInfo.getExcludedConfigTypes()) {
        if (!configurationModules.containsKey(excludedType)) {
          ConfigurationInfo configInfo =
              new ConfigurationInfo(
                  Collections.<PropertyInfo>emptyList(), Collections.<String, String>emptyMap());
          ConfigurationModule config = new ConfigurationModule(excludedType, configInfo);

          config.setDeleted(true);
          configurationModules.put(excludedType, config);
        }
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Merges service properties from parent into the the service properties of this this service.
   * Current properties overrides properties with same name from parent
   *
   * @param other service properties to merge with the current service property list
   */
  private void mergeServiceProperties(List<ServicePropertyInfo> other) {
    if (!other.isEmpty()) {
      List<ServicePropertyInfo> servicePropertyList = serviceInfo.getServicePropertyList();
      List<ServicePropertyInfo> servicePropertiesToAdd = Lists.newArrayList();

      Set<String> servicePropertyNames =
          Sets.newTreeSet(
              Iterables.transform(
                  servicePropertyList,
                  new Function<ServicePropertyInfo, String>() {
                    @Nullable
                    @Override
                    public String apply(ServicePropertyInfo serviceProperty) {
                      return serviceProperty.getName();
                    }
                  }));

      for (ServicePropertyInfo otherServiceProperty : other) {
        if (!servicePropertyNames.contains(otherServiceProperty.getName()))
          servicePropertiesToAdd.add(otherServiceProperty);
      }

      List<ServicePropertyInfo> mergedServicePropertyList =
          ImmutableList.<ServicePropertyInfo>builder()
              .addAll(servicePropertyList)
              .addAll(servicePropertiesToAdd)
              .build();

      serviceInfo.setServicePropertyList(mergedServicePropertyList);

      validateServiceInfo();
    }
  }
Ejemplo n.º 3
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.º 4
0
  @Test
  public void testResolve_RequiredServices() throws Exception {
    List<String> requiredServices = new ArrayList<String>();
    requiredServices.add("foo");
    requiredServices.add("bar");

    // specified in child only
    ServiceInfo info = new ServiceInfo();
    ServiceInfo parentInfo = new ServiceInfo();
    info.setRequiredServices(requiredServices);

    ServiceModule service = resolveService(info, parentInfo);
    assertEquals(requiredServices, service.getModuleInfo().getRequiredServices());

    // specified in parent only
    info.setRequiredServices(null);
    parentInfo.setRequiredServices(requiredServices);

    service = resolveService(info, parentInfo);
    assertEquals(requiredServices, service.getModuleInfo().getRequiredServices());

    // specified in both
    info.setRequiredServices(requiredServices);
    parentInfo.setRequiredServices(Collections.singletonList("other"));

    service = resolveService(info, parentInfo);
    assertEquals(requiredServices, service.getModuleInfo().getRequiredServices());

    // not set in either
    info.setRequiredServices(null);
    parentInfo.setRequiredServices(null);

    service = resolveService(info, parentInfo);
    assertTrue(service.getModuleInfo().getRequiredServices().isEmpty());
  }
Ejemplo n.º 5
0
  @Test
  public void testResolve_Configuration__ExcludedTypes__ParentType() throws Exception {
    // child
    ServiceInfo info = new ServiceInfo();
    info.setExcludedConfigTypes(Collections.singleton("BAR"));

    // FOO
    Collection<PropertyInfo> fooProperties = new ArrayList<PropertyInfo>();
    PropertyInfo prop1 = new PropertyInfo();
    prop1.setName("name1");
    prop1.setValue("val1");
    fooProperties.add(prop1);
    PropertyInfo prop2 = new PropertyInfo();
    prop2.setName("name2");
    prop2.setValue("val2");
    fooProperties.add(prop2);

    ConfigurationModule childConfigModule = createConfigurationModule("FOO", fooProperties);
    Collection<ConfigurationModule> childConfigModules = new ArrayList<ConfigurationModule>();
    childConfigModules.add(childConfigModule);

    // parent
    ServiceInfo parentInfo = new ServiceInfo();

    // BAR
    Collection<PropertyInfo> barProperties = new ArrayList<PropertyInfo>();
    PropertyInfo prop3 = new PropertyInfo();
    prop3.setName("name1");
    prop3.setValue("val3");
    barProperties.add(prop3);

    ConfigurationModule parentConfigModule = createConfigurationModule("BAR", barProperties);
    Collection<ConfigurationModule> parentConfigModules = new ArrayList<ConfigurationModule>();
    parentConfigModules.add(parentConfigModule);

    // create service modules
    ServiceModule service = createServiceModule(info, childConfigModules);
    ServiceModule parentService = createServiceModule(parentInfo, parentConfigModules);
    // resolve child with parent
    resolveService(service, parentService);
    // assertions
    List<PropertyInfo> properties = service.getModuleInfo().getProperties();
    assertEquals(2, properties.size());

    Map<String, Map<String, Map<String, String>>> attributes =
        service.getModuleInfo().getConfigTypeAttributes();
    assertEquals(1, attributes.size());
    assertTrue(attributes.containsKey("FOO"));

    Map<String, Map<String, Map<String, String>>> parentAttributes =
        parentService.getModuleInfo().getConfigTypeAttributes();
    assertEquals(1, parentAttributes.size());
    assertTrue(parentAttributes.containsKey("BAR"));
  }
Ejemplo n.º 6
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.º 7
0
 /**
  * Merge components with the parent configurations. This will update the child component module
  * set as well as the underlying info instances.
  *
  * @param parent parent service module
  * @param allStacks all stack modules
  * @param commonServices common service modules
  */
 private void mergeComponents(
     ServiceModule parent,
     Map<String, StackModule> allStacks,
     Map<String, ServiceModule> commonServices)
     throws AmbariException {
   serviceInfo.getComponents().clear();
   Collection<ComponentModule> mergedModules =
       mergeChildModules(allStacks, commonServices, componentModules, parent.componentModules);
   componentModules.clear();
   for (ComponentModule module : mergedModules) {
     componentModules.put(module.getId(), module);
     serviceInfo.getComponents().add(module.getModuleInfo());
   }
 }
Ejemplo n.º 8
0
  @Test
  public void testResolve_CustomCommands() throws Exception {
    List<CustomCommandDefinition> customCommands = new ArrayList<CustomCommandDefinition>();
    CustomCommandDefinition cmd1 = new CustomCommandDefinition();
    setPrivateField(cmd1, "name", "cmd1");
    setPrivateField(cmd1, "background", false);
    CustomCommandDefinition cmd2 = new CustomCommandDefinition();
    setPrivateField(cmd2, "name", "cmd2");
    customCommands.add(cmd1);
    customCommands.add(cmd2);

    // specified in child only
    ServiceInfo info = new ServiceInfo();
    ServiceInfo parentInfo = new ServiceInfo();
    info.setCustomCommands(customCommands);

    ServiceModule service = resolveService(info, parentInfo);
    assertEquals(customCommands, service.getModuleInfo().getCustomCommands());

    // specified in parent only
    info.setCustomCommands(null);
    parentInfo.setCustomCommands(customCommands);

    service = resolveService(info, parentInfo);
    assertEquals(customCommands, service.getModuleInfo().getCustomCommands());

    // specified in both
    List<CustomCommandDefinition> parentCustomCommands = new ArrayList<CustomCommandDefinition>();
    CustomCommandDefinition cmd3 = new CustomCommandDefinition();
    setPrivateField(cmd3, "name", "cmd1");
    setPrivateField(cmd3, "background", true);
    CustomCommandDefinition cmd4 = new CustomCommandDefinition();
    setPrivateField(cmd4, "name", "cmd4");
    parentCustomCommands.add(cmd3);
    parentCustomCommands.add(cmd4);

    info.setCustomCommands(customCommands);
    parentInfo.setCustomCommands(parentCustomCommands);

    service = resolveService(info, parentInfo);
    Collection<CustomCommandDefinition> mergedCommands =
        service.getModuleInfo().getCustomCommands();
    assertEquals(3, mergedCommands.size());
    assertTrue(mergedCommands.contains(cmd2));
    assertTrue(mergedCommands.contains(cmd3));
    assertTrue(mergedCommands.contains(cmd4));

    // not set in either
    info.setCustomCommands(null);
    parentInfo.setCustomCommands(null);

    service = resolveService(info, parentInfo);
    assertTrue(service.getModuleInfo().getCustomCommands().isEmpty());
  }
Ejemplo n.º 9
0
  @Test
  public void testResolve_Configuration__ExcludedTypes() throws Exception {
    ServiceInfo info = new ServiceInfo();
    info.setExcludedConfigTypes(Collections.singleton("BAR"));

    // FOO
    Collection<PropertyInfo> fooProperties = new ArrayList<PropertyInfo>();
    PropertyInfo prop1 = new PropertyInfo();
    prop1.setName("name1");
    prop1.setValue("val1");
    fooProperties.add(prop1);
    PropertyInfo prop2 = new PropertyInfo();
    prop2.setName("name2");
    prop2.setValue("val2");
    fooProperties.add(prop2);

    // BAR
    Collection<PropertyInfo> barProperties = new ArrayList<PropertyInfo>();
    PropertyInfo prop3 = new PropertyInfo();
    prop3.setName("name1");
    prop3.setValue("val3");
    barProperties.add(prop3);

    // OTHER
    Collection<PropertyInfo> otherProperties = new ArrayList<PropertyInfo>();
    PropertyInfo prop4 = new PropertyInfo();
    prop4.setName("name1");
    prop4.setValue("val4");
    otherProperties.add(prop4);

    ConfigurationModule configModule1 = createConfigurationModule("FOO", fooProperties);
    ConfigurationModule configModule2 = createConfigurationModule("BAR", barProperties);
    ConfigurationModule configModule3 = createConfigurationModule("OTHER", otherProperties);
    Collection<ConfigurationModule> configModules = new ArrayList<ConfigurationModule>();
    configModules.add(configModule1);
    configModules.add(configModule2);
    configModules.add(configModule3);

    ServiceModule service = createServiceModule(info, configModules);

    List<PropertyInfo> properties = service.getModuleInfo().getProperties();
    assertEquals(4, properties.size());

    Map<String, Map<String, Map<String, String>>> attributes =
        service.getModuleInfo().getConfigTypeAttributes();
    assertEquals(2, attributes.size());
    assertTrue(attributes.containsKey("FOO"));
    assertTrue(attributes.containsKey("OTHER"));
  }
Ejemplo n.º 10
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.º 11
0
 /** Finalize service configurations. Ensure that all default type attributes are set. */
 private void finalizeConfiguration() {
   for (ConfigurationModule config : configurationModules.values()) {
     ConfigurationInfo configInfo = config.getModuleInfo();
     configInfo.ensureDefaultAttributes();
     serviceInfo.setTypeAttributes(config.getConfigType(), configInfo.getAttributes());
   }
 }
Ejemplo n.º 12
0
  @Test
  public void testResolve_RestartRequiredAfterChange() throws Exception {
    Boolean isRestartRequired = true;

    // specified in child only
    ServiceInfo info = new ServiceInfo();
    ServiceInfo parentInfo = new ServiceInfo();
    info.setRestartRequiredAfterChange(isRestartRequired);

    ServiceModule service = resolveService(info, parentInfo);
    assertEquals(isRestartRequired, service.getModuleInfo().isRestartRequiredAfterChange());

    // specified in parent only
    info.setRestartRequiredAfterChange(null);
    parentInfo.setRestartRequiredAfterChange(isRestartRequired);

    service = resolveService(info, parentInfo);
    assertEquals(isRestartRequired, service.getModuleInfo().isRestartRequiredAfterChange());

    // specified in both
    info.setRestartRequiredAfterChange(isRestartRequired);
    parentInfo.setRestartRequiredAfterChange(false);

    service = resolveService(info, parentInfo);
    assertEquals(isRestartRequired, service.getModuleInfo().isRestartRequiredAfterChange());
  }
Ejemplo n.º 13
0
  @Test
  public void testResolve_MonitoringService() throws Exception {
    Boolean isMonitoringService = true;

    // specified in child only
    ServiceInfo info = new ServiceInfo();
    ServiceInfo parentInfo = new ServiceInfo();
    info.setMonitoringService(isMonitoringService);

    ServiceModule service = resolveService(info, parentInfo);
    assertEquals(isMonitoringService, service.getModuleInfo().isMonitoringService());

    // specified in parent only
    info.setMonitoringService(null);
    parentInfo.setMonitoringService(isMonitoringService);

    service = resolveService(info, parentInfo);
    assertEquals(isMonitoringService, service.getModuleInfo().isMonitoringService());

    // specified in both
    info.setMonitoringService(isMonitoringService);
    parentInfo.setMonitoringService(false);

    service = resolveService(info, parentInfo);
    assertEquals(isMonitoringService, service.getModuleInfo().isMonitoringService());
  }
Ejemplo n.º 14
0
  @Test
  public void testResolve_OsSpecifics() throws Exception {
    Map<String, ServiceOsSpecific> osSpecifics = new HashMap<String, ServiceOsSpecific>();
    osSpecifics.put("foo", new ServiceOsSpecific());

    // specified in child only
    ServiceInfo info = new ServiceInfo();
    ServiceInfo parentInfo = new ServiceInfo();
    info.setOsSpecifics(osSpecifics);

    ServiceModule service = resolveService(info, parentInfo);
    assertEquals(osSpecifics, service.getModuleInfo().getOsSpecifics());

    // specified in parent only
    info.setOsSpecifics(null);
    parentInfo.setOsSpecifics(osSpecifics);

    service = resolveService(info, parentInfo);
    assertEquals(osSpecifics, service.getModuleInfo().getOsSpecifics());

    // specified in both
    Map<String, ServiceOsSpecific> osSpecifics2 = new HashMap<String, ServiceOsSpecific>();
    osSpecifics.put("bar", new ServiceOsSpecific());

    info.setOsSpecifics(osSpecifics);
    parentInfo.setOsSpecifics(osSpecifics2);

    service = resolveService(info, parentInfo);
    assertEquals(osSpecifics, service.getModuleInfo().getOsSpecifics());
  }
Ejemplo n.º 15
0
  @Test
  public void testResolve_CommandScript() throws Exception {
    CommandScriptDefinition commandScript = new CommandScriptDefinition();

    // specified in child only
    ServiceInfo info = new ServiceInfo();
    ServiceInfo parentInfo = new ServiceInfo();
    info.setCommandScript(commandScript);

    ServiceModule service = resolveService(info, parentInfo);
    assertEquals(commandScript, service.getModuleInfo().getCommandScript());

    // specified in parent only
    info.setCommandScript(null);
    parentInfo.setCommandScript(commandScript);

    service = resolveService(info, parentInfo);
    assertEquals(commandScript, service.getModuleInfo().getCommandScript());

    // specified in both
    CommandScriptDefinition commandScript2 = new CommandScriptDefinition();

    info.setCommandScript(commandScript);
    parentInfo.setCommandScript(commandScript2);

    service = resolveService(info, parentInfo);
    assertEquals(commandScript, service.getModuleInfo().getCommandScript());
  }
Ejemplo n.º 16
0
  @Test
  public void testResolve_Comment() throws Exception {
    String comment = "test comment";

    // comment specified in child only
    ServiceInfo info = new ServiceInfo();
    ServiceInfo parentInfo = new ServiceInfo();
    info.setComment(comment);

    ServiceModule service = resolveService(info, parentInfo);
    assertEquals(comment, service.getModuleInfo().getComment());

    // comment specified in parent only
    info.setComment(null);
    parentInfo.setComment(comment);

    service = resolveService(info, parentInfo);
    assertEquals(comment, service.getModuleInfo().getComment());

    // set in both
    info.setComment(comment);
    parentInfo.setComment("other comment");

    service = resolveService(info, parentInfo);
    assertEquals(comment, service.getModuleInfo().getComment());
  }
Ejemplo n.º 17
0
  @Test
  public void testResolve_DisplayName() throws Exception {
    String displayName = "test_display_name";

    // specified in child only
    ServiceInfo info = new ServiceInfo();
    ServiceInfo parentInfo = new ServiceInfo();
    info.setDisplayName(displayName);

    ServiceModule service = resolveService(info, parentInfo);
    assertEquals(displayName, service.getModuleInfo().getDisplayName());

    // specified in parent only
    info.setDisplayName(null);
    parentInfo.setDisplayName(displayName);

    service = resolveService(info, parentInfo);
    assertEquals(displayName, service.getModuleInfo().getDisplayName());

    // specified in both
    info.setDisplayName(displayName);
    parentInfo.setDisplayName("other display name");

    service = resolveService(info, parentInfo);
    assertEquals(displayName, service.getModuleInfo().getDisplayName());
  }
Ejemplo n.º 18
0
  @Test
  public void testResolve_Version() throws Exception {
    String version = "1.1";

    // specified in child only
    ServiceInfo info = new ServiceInfo();
    ServiceInfo parentInfo = new ServiceInfo();
    info.setVersion(version);

    ServiceModule service = resolveService(info, parentInfo);
    assertEquals(version, service.getModuleInfo().getVersion());

    // specified in parent only
    info.setVersion(null);
    parentInfo.setVersion(version);

    service = resolveService(info, parentInfo);
    assertEquals(version, service.getModuleInfo().getVersion());

    // specified in both
    info.setVersion(version);
    parentInfo.setVersion("1.0");

    service = resolveService(info, parentInfo);
    assertEquals(version, service.getModuleInfo().getVersion());
  }
Ejemplo n.º 19
0
  /** Merge theme modules. */
  private void mergeThemes(
      ServiceModule parent,
      Map<String, StackModule> allStacks,
      Map<String, ServiceModule> commonServices)
      throws AmbariException {
    Collection<ThemeModule> mergedModules =
        mergeChildModules(allStacks, commonServices, themeModules, parent.themeModules);

    for (ThemeModule mergedModule : mergedModules) {
      themeModules.put(mergedModule.getId(), mergedModule);
      ThemeInfo moduleInfo = mergedModule.getModuleInfo();
      if (!moduleInfo.isDeleted()) {
        serviceInfo.getThemesMap().put(moduleInfo.getFileName(), moduleInfo);
      } else {
        serviceInfo.getThemesMap().remove(moduleInfo.getFileName());
      }
    }
  }
Ejemplo n.º 20
0
  /**
   * Merge configuration dependencies with parent. Child values override parent values.
   *
   * @param parent parent service module
   */
  private void mergeConfigDependencies(ServiceInfo parent) {
    // currently there is no way to remove an inherited config dependency
    List<String> configDependencies = serviceInfo.getConfigDependencies();
    List<String> parentConfigDependencies =
        parent.getConfigDependencies() != null
            ? parent.getConfigDependencies()
            : Collections.<String>emptyList();

    if (configDependencies == null) {
      serviceInfo.setConfigDependencies(parentConfigDependencies);
    } else {
      for (String parentDependency : parentConfigDependencies) {
        if (!configDependencies.contains(parentDependency)) {
          configDependencies.add(parentDependency);
        }
      }
    }
  }
Ejemplo n.º 21
0
 @Override
 public void finalizeModule() {
   finalizeChildModules(configurationModules.values());
   finalizeChildModules(componentModules.values());
   finalizeConfiguration();
   if (serviceInfo.getCommandScript() != null && !isDeleted()) {
     stackContext.registerServiceCheck(getId());
   }
 }
Ejemplo n.º 22
0
  private void populateThemeModules() {

    if (serviceInfo.getThemesDir() == null) {
      serviceInfo.setThemesDir(AmbariMetaInfo.SERVICE_THEMES_FOLDER_NAME);
    }

    String themesDir =
        serviceDirectory.getAbsolutePath() + File.separator + serviceInfo.getThemesDir();

    if (serviceInfo.getThemes() != null) {
      for (ThemeInfo themeInfo : serviceInfo.getThemes()) {
        File themeFile = new File(themesDir + File.separator + themeInfo.getFileName());
        ThemeModule module = new ThemeModule(themeFile, themeInfo);
        themeModules.put(module.getId(), module);
      }
    }

    // lets not fail if theme contain errors
  }
Ejemplo n.º 23
0
  /**
   * Merge configurations with the parent configurations. This will update the child configuration
   * module set as well as the underlying info instances.
   *
   * @param parent parent service module
   * @param allStacks all stack modules
   * @param commonServices common service modules
   */
  private void mergeConfigurations(
      ServiceModule parent,
      Map<String, StackModule> allStacks,
      Map<String, ServiceModule> commonServices)
      throws AmbariException {
    serviceInfo.getProperties().clear();
    serviceInfo.setAllConfigAttributes(new HashMap<String, Map<String, Map<String, String>>>());

    Collection<ConfigurationModule> mergedModules =
        mergeChildModules(
            allStacks, commonServices, configurationModules, parent.configurationModules);

    for (ConfigurationModule module : mergedModules) {
      configurationModules.put(module.getId(), module);
      if (!module.isDeleted()) {
        serviceInfo.getProperties().addAll(module.getModuleInfo().getProperties());
        serviceInfo.setTypeAttributes(
            module.getConfigType(), module.getModuleInfo().getAttributes());
      }
    }
  }
Ejemplo n.º 24
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.º 25
0
  @Test
  public void testResolve_ConfigDependencies() throws Exception {
    List<String> configDependencies = new ArrayList<String>();
    configDependencies.add("foo");
    configDependencies.add("bar");

    // specified in child only
    ServiceInfo info = new ServiceInfo();
    ServiceInfo parentInfo = new ServiceInfo();
    info.setConfigDependencies(configDependencies);

    ServiceModule service = resolveService(info, parentInfo);
    assertEquals(configDependencies, service.getModuleInfo().getConfigDependencies());

    // specified in parent only
    info.setConfigDependencies(null);
    parentInfo.setConfigDependencies(configDependencies);

    service = resolveService(info, parentInfo);
    assertEquals(configDependencies, service.getModuleInfo().getConfigDependencies());

    // specified in both
    List<String> parentCustomCommands = new ArrayList<String>();
    parentCustomCommands.add("bar");
    parentCustomCommands.add("other");

    info.setConfigDependencies(configDependencies);
    parentInfo.setConfigDependencies(parentCustomCommands);

    service = resolveService(info, parentInfo);
    Collection<String> mergedConfigDependencies = service.getModuleInfo().getConfigDependencies();
    assertEquals(3, mergedConfigDependencies.size());
    assertTrue(mergedConfigDependencies.contains("foo"));
    assertTrue(mergedConfigDependencies.contains("bar"));
    assertTrue(mergedConfigDependencies.contains("other"));

    // not set in either
    info.setConfigDependencies(null);
    parentInfo.setConfigDependencies(null);

    service = resolveService(info, parentInfo);
    assertTrue(service.getModuleInfo().getConfigDependencies().isEmpty());
  }
Ejemplo n.º 26
0
  @Test
  public void testMerge_Configuration__ExcludedTypes() throws Exception {
    // child
    ServiceInfo info = new ServiceInfo();
    Set<String> childExcludedConfigTypes = new HashSet<String>();
    childExcludedConfigTypes.add("FOO");
    info.setExcludedConfigTypes(childExcludedConfigTypes);

    // FOO
    Collection<PropertyInfo> fooProperties = new ArrayList<PropertyInfo>();

    ConfigurationModule childConfigModule = createConfigurationModule("FOO", fooProperties);
    Collection<ConfigurationModule> childConfigModules = new ArrayList<ConfigurationModule>();
    childConfigModules.add(childConfigModule);

    // parent
    ServiceInfo parentInfo = new ServiceInfo();
    Set<String> parentExcludedConfigTypes = new HashSet<String>();
    childExcludedConfigTypes.add("BAR");
    info.setExcludedConfigTypes(childExcludedConfigTypes);
    parentInfo.setExcludedConfigTypes(parentExcludedConfigTypes);
    // BAR
    Collection<PropertyInfo> barProperties = new ArrayList<PropertyInfo>();

    ConfigurationModule parentConfigModule = createConfigurationModule("BAR", barProperties);
    Collection<ConfigurationModule> parentConfigModules = new ArrayList<ConfigurationModule>();
    parentConfigModules.add(parentConfigModule);

    // create service modules
    ServiceModule service = createServiceModule(info, childConfigModules);
    ServiceModule parentService = createServiceModule(parentInfo, parentConfigModules);
    // resolve child with parent

    resolveService(service, parentService);

    // resolveService(service, parentService);
    assertEquals(2, service.getModuleInfo().getExcludedConfigTypes().size());
  }
Ejemplo n.º 27
0
 /**
  * Merge excluded configs types with parent. Child values override parent values.
  *
  * @param parent parent service module
  */
 private void mergeExcludedConfigTypes(ServiceInfo parent) {
   if (serviceInfo.getExcludedConfigTypes() == null) {
     serviceInfo.setExcludedConfigTypes(parent.getExcludedConfigTypes());
   } else if (parent.getExcludedConfigTypes() != null) {
     Set<String> resultExcludedConfigTypes = serviceInfo.getExcludedConfigTypes();
     for (String excludedType : parent.getExcludedConfigTypes()) {
       if (!resultExcludedConfigTypes.contains(excludedType)) {
         resultExcludedConfigTypes.add(excludedType);
       }
     }
     serviceInfo.setExcludedConfigTypes(resultExcludedConfigTypes);
   }
 }
Ejemplo n.º 28
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.º 29
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.º 30
0
 private void validateServiceInfo() {
   if (!serviceInfo.isValid()) {
     setValid(false);
     setErrors(serviceInfo.getErrors());
   }
 }