Пример #1
0
    public MockInventoryManager() {
      super(pcConfig, null, pluginManager, new EventManager(pcConfig));
      platformType =
          new ResourceType(
              "platformResourceTypeName", "pluginName", ResourceCategory.PLATFORM, null);
      bundleHandlerType =
          new ResourceType("bhRTypeName", "pluginName", ResourceCategory.SERVER, platformType);
      serverTypeFS =
          new ResourceType(
              "typeName-fileSystem", "pluginName", ResourceCategory.SERVER, platformType);
      serverTypePC =
          new ResourceType(
              "typeName-plugConfig", "pluginName", ResourceCategory.SERVER, platformType);
      serverTypeRC =
          new ResourceType(
              "typeName-reSconfig", "pluginName", ResourceCategory.SERVER, platformType);
      serverTypeMT =
          new ResourceType("typeName-trait", "pluginName", ResourceCategory.SERVER, platformType);

      int id = 1;
      platform = new Resource("platformKey", "platformName", platformType);
      platform.setId(id++);
      bundleHandler = new Resource("bhKey", "bhName", bundleHandlerType);
      bundleHandler.setId(id++);
      bundleHandler.setParentResource(platform);
      bundleHandler.setUuid(UUID.randomUUID().toString());
      serverFS = new Resource("serverKey-fileSystem", "serverName-fileSystem", serverTypeFS);
      serverFS.setId(id++);
      serverFS.setParentResource(platform);
      serverPC = new Resource("serverKey-plugConfig", "serverName-plugConfig", serverTypePC);
      serverPC.setId(id++);
      serverPC.setParentResource(platform);
      serverRC = new Resource("serverKey-resConfig", "serverName-resConfig", serverTypeRC);
      serverRC.setId(id++);
      serverRC.setParentResource(platform);
      serverMT = new Resource("serverKey-traitConfig", "serverName-traitConfig", serverTypeMT);
      serverMT.setId(id++);
      serverMT.setParentResource(platform);

      typeResourceMap.put(platformType, platform);
      typeResourceMap.put(bundleHandlerType, bundleHandler);
      typeResourceMap.put(serverTypeFS, serverFS);
      typeResourceMap.put(serverTypePC, serverPC);
      typeResourceMap.put(serverTypeRC, serverRC);
      typeResourceMap.put(serverTypeMT, serverMT);

      ResourceContainer platformContainer = new ResourceContainer(platform, null);
      ResourceContainer bundleHandlerContainer = new ResourceContainer(bundleHandler, null);
      ResourceContainer serverContainerFS = new ResourceContainer(serverFS, null);
      ResourceContainer serverContainerPC = new ResourceContainer(serverPC, null);
      ResourceContainer serverContainerRC = new ResourceContainer(serverRC, null);
      ResourceContainer serverContainerMT = new ResourceContainer(serverMT, null);
      idResourceContainerMap.put(platform.getId(), platformContainer);
      idResourceContainerMap.put(bundleHandler.getId(), bundleHandlerContainer);
      idResourceContainerMap.put(serverFS.getId(), serverContainerFS);
      idResourceContainerMap.put(serverPC.getId(), serverContainerPC);
      idResourceContainerMap.put(serverRC.getId(), serverContainerRC);
      idResourceContainerMap.put(serverMT.getId(), serverContainerMT);

      bundleHandlerContainer.setResourceContext(new MockResourceContext(bundleHandler));

      // each different resource type that supports bundle deployments needs to define its
      // bundle configuration to denote where the base directory location is found.
      // Today we support four ways: via plugin config property, resource config property,
      // measurement trait value, or strictly on the root file system (using no resource specific
      // value)
      ResourceTypeBundleConfiguration rtbc =
          new ResourceTypeBundleConfiguration(new Configuration());
      rtbc.addBundleDestinationBaseDirectory(
          BUNDLE_CONFIG_NAME_FS, Context.fileSystem.name(), BUNDLE_CONFIG_CONTEXT_VALUE_FS, null);
      serverTypeFS.setResourceTypeBundleConfiguration(rtbc);

      rtbc = new ResourceTypeBundleConfiguration(new Configuration());
      rtbc.addBundleDestinationBaseDirectory(
          BUNDLE_CONFIG_NAME_PC,
          Context.pluginConfiguration.name(),
          BUNDLE_CONFIG_CONTEXT_VALUE_PC,
          null);
      serverTypePC.setResourceTypeBundleConfiguration(rtbc);

      rtbc = new ResourceTypeBundleConfiguration(new Configuration());
      rtbc.addBundleDestinationBaseDirectory(
          BUNDLE_CONFIG_NAME_RC,
          Context.resourceConfiguration.name(),
          BUNDLE_CONFIG_CONTEXT_VALUE_RC,
          null);
      serverTypeRC.setResourceTypeBundleConfiguration(rtbc);

      rtbc = new ResourceTypeBundleConfiguration(new Configuration());
      rtbc.addBundleDestinationBaseDirectory(
          BUNDLE_CONFIG_NAME_MT,
          Context.measurementTrait.name(),
          BUNDLE_CONFIG_CONTEXT_VALUE_MT,
          null);
      serverTypeMT.setResourceTypeBundleConfiguration(rtbc);

      // each different resource needs to specify where exactly it wants the bundles deployed
      // using the different contexts that are supported.
      Configuration pluginConfiguration = new Configuration();
      pluginConfiguration.put(
          new PropertySimple(BUNDLE_CONFIG_CONTEXT_VALUE_PC, BUNDLE_CONFIG_LOCATION_PC));
      serverPC.setPluginConfiguration(pluginConfiguration);

      Configuration resourceConfiguration = new Configuration();
      resourceConfiguration.put(
          new PropertySimple(BUNDLE_CONFIG_CONTEXT_VALUE_RC, BUNDLE_CONFIG_LOCATION_RC));
      serverRC.setResourceConfiguration(resourceConfiguration);

      MeasurementDefinition definition =
          new MeasurementDefinition(serverTypeMT, BUNDLE_CONFIG_CONTEXT_VALUE_MT);
      definition.setDataType(DataType.TRAIT);
      definition.setId(123);
      MeasurementSchedule schedule = new MeasurementSchedule(definition, serverMT);
      schedule.setId(123123);
      MeasurementScheduleRequest scheduleRequest = new MeasurementScheduleRequest(schedule);
      Set<MeasurementScheduleRequest> schedules = new HashSet<MeasurementScheduleRequest>(1);
      schedules.add(scheduleRequest);
      serverContainerMT.setMeasurementSchedule(schedules);
    }
Пример #2
0
  public void checkConfigurations(Resource resource, boolean checkChildren) {
    ResourceContainer resourceContainer = this.inventoryManager.getResourceContainer(resource);
    ConfigurationFacet resourceComponent = null;
    ResourceType resourceType = resource.getResourceType();

    if (resourceContainer != null
        && resourceContainer.getAvailability() != null
        && resourceContainer.getAvailability().getAvailabilityType() == AvailabilityType.UP) {

      try {
        resourceComponent =
            resourceContainer.createResourceComponentProxy(
                ConfigurationFacet.class,
                FacetLockType.NONE,
                CONFIGURATION_CHECK_TIMEOUT,
                true,
                false);
      } catch (PluginContainerException e) {
        // Expecting when the resource does not support configuration management
      }

      if (resourceComponent != null) {
        // Only report availability for committed resources; don't bother with new, ignored or
        // deleted resources.
        if (resource.getInventoryStatus() == InventoryStatus.COMMITTED
            && resourceType.getResourceConfigurationDefinition() != null) {

          if (log.isErrorEnabled())
            log.debug("Checking for updated resource configuration on: " + resource);

          ConfigurationUpdateRequest request =
              new ConfigurationUpdateRequest(
                  0, resource.getResourceConfiguration(), resource.getId());

          try {

            Configuration liveConfiguration = resourceComponent.loadResourceConfiguration();

            if (liveConfiguration != null) {
              ConfigurationDefinition configurationDefinition =
                  resourceType.getResourceConfigurationDefinition();

              // Normalize and validate the config.
              ConfigurationUtility.normalizeConfiguration(
                  liveConfiguration, configurationDefinition);
              List<String> errorMessages =
                  ConfigurationUtility.validateConfiguration(
                      liveConfiguration, configurationDefinition);
              for (String errorMessage : errorMessages) {
                log.warn(
                    "Plugin Error: Invalid "
                        + resourceType.getName()
                        + " resource configuration returned by "
                        + resourceType.getPlugin()
                        + " plugin - "
                        + errorMessage);
              }

              Configuration original = resource.getResourceConfiguration();
              if (!liveConfiguration.equals(original)) {
                log.info("New configuration version detected on resource: " + resource);
                this.configurationServerService.persistUpdatedResourceConfiguration(
                    resource.getId(), liveConfiguration);
                resource.setResourceConfiguration(liveConfiguration);
              }
            }
          } catch (Throwable t) {
            log.warn("Unable to check for updated configuration", t);
          }
        }
      }

      if (checkChildren) {
        // Avoid concurrent mod exceptions during potentially long duration issues
        Set<Resource> childSet = new HashSet<Resource>(resource.getChildResources());
        for (Resource child : childSet) {
          try {
            checkConfigurations(child, true);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
    }
  }