Ejemplo n.º 1
0
 public String toString() {
   return "["
       + resourceId
       + "] "
       + resource.getName()
       + " ("
       + resource.getResourceType().getName()
       + "::"
       + resource.getResourceType().getPlugin()
       + ")";
 }
Ejemplo n.º 2
0
 private void initConfigDefs() {
   this.resourceConfigurationDefinition =
       remoteClient
           .getConfigurationManager()
           .getResourceConfigurationDefinitionWithTemplatesForResourceType(
               remoteClient.getSubject(), resource.getResourceType().getId());
   this.pluginConfigurationDefinition =
       remoteClient
           .getConfigurationManager()
           .getPluginConfigurationDefinitionForResourceType(
               remoteClient.getSubject(), resource.getResourceType().getId());
 }
Ejemplo n.º 3
0
  public void init() {

    this.resource =
        remoteClient.getResourceManager().getResource(remoteClient.getSubject(), resourceId);

    // Lazy init children, not here
    initMeasurements();
    initOperations();
    initConfigDefs();
    initContent();

    List<PackageType> packageTypes = new ArrayList<PackageType>();
    for (ContentType ct : contentTypes.values()) {
      packageTypes.add(ct.getPackageType());
    }

    fingerprint =
        new ResourceTypeFingerprint(
            resource.getResourceType(),
            measurementDefinitions,
            operationDefinitions,
            packageTypes,
            pluginConfigurationDefinition,
            resourceConfigurationDefinition);
  }
  @Override
  protected void onInit() {

    // To properly filter Create Child and Import menus we need existing singleton child resources.
    // If the
    // user has create permission and the parent type has singleton child types and creatable or
    // importable child
    // types, perform an async call to fetch the singleton children. If we make the async call don't
    // declare this
    // instance initialized until after it completes as we must have the children before the menu
    // buttons can be drawn.

    final Resource parentResource = parentResourceComposite.getResource();
    ResourceType parentType = parentResource.getResourceType();
    creatableChildTypes = getCreatableChildTypes(parentType);
    importableChildTypes = getImportableChildTypes(parentType);
    hasCreatableTypes = !creatableChildTypes.isEmpty();
    hasImportableTypes = !importableChildTypes.isEmpty();
    refreshSingletons(
        parentResource,
        new AsyncCallback<PageList<Resource>>() {

          public void onFailure(Throwable caught) {
            ResourceCompositeSearchView.super.onInit();
            initialized = true;
          }

          public void onSuccess(PageList<Resource> result) {
            ResourceCompositeSearchView.super.onInit();
            initialized = true;
          }
        });
  }
Ejemplo n.º 5
0
    @Override
    public ListGridRecord copyValues(AlertDefinition from) {
      // in order to support sorting our list grid on the parent and resource columns,
      // we have to assign these to something that is sortable
      ListGridRecord record = super.copyValues(from);
      Resource resource = from.getResource();

      record.setAttribute(FIELD_RESOURCE, resource.getName());

      Integer parentId =
          from.getParentId(); // a valid non-zero number means the alert def came from a template
      AlertDefinition groupAlertDefinition = from.getGroupAlertDefinition();

      if (parentId != null && parentId.intValue() > 0) {
        record.setAttribute(FIELD_PARENT, "<b>" + MSG.view_alert_definition_for_type() + "</b>");
      } else if (groupAlertDefinition != null) {
        record.setAttribute(FIELD_PARENT, "<b>" + MSG.view_alert_definition_for_group() + "</b>");
      }

      // for ancestry handling
      record.setAttribute(AncestryUtil.RESOURCE_ID, resource.getId());
      record.setAttribute(AncestryUtil.RESOURCE_NAME, resource.getName());
      record.setAttribute(AncestryUtil.RESOURCE_ANCESTRY, resource.getAncestry());
      record.setAttribute(AncestryUtil.RESOURCE_TYPE_ID, resource.getResourceType().getId());

      return record;
    }
Ejemplo n.º 6
0
  private void setTitle(HttpServletRequest request, Portal portal, String titleName)
      throws Exception {
    Resource resource = RequestUtils.getResource(request);
    ResourceGroup group = RequestUtils.getResourceGroupIfExists(request);
    ResourceType type;
    if (resource != null) {
      // resource alert definition
      type = resource.getResourceType();
    } else if (group != null) {
      // group alert definition
      type = group.getResourceType();
    } else {
      // template alert definition
      type = RequestUtils.getResourceType(request);
    }

    ResourceCategory category = type.getCategory();

    titleName = StringUtil.replace(titleName, "platform", category.toString().toLowerCase());

    portal.setName(titleName);

    // if there's an alert definition available, set our second
    // title parameter to its name
    try {
      AlertDefinition alertDef = AlertDefUtil.getAlertDefinition(request);
      request.setAttribute(Constants.TITLE_PARAM2_ATTR, alertDef.getName());
    } catch (ParameterNotFoundException e) {
      // it's okay
      log.trace("couldn't find alert definition: " + e.getMessage());
    }
  }
  private static Resource convertToPojoResource(Resource resource, boolean includeDescendants) {
    Resource pojoResource = new Resource(resource.getId());
    pojoResource.setUuid(resource.getUuid());
    pojoResource.setResourceKey(resource.getResourceKey());
    pojoResource.setResourceType(resource.getResourceType());
    pojoResource.setMtime(resource.getMtime());
    pojoResource.setInventoryStatus(resource.getInventoryStatus());
    Configuration pcCopy = resource.getPluginConfiguration();
    if (pcCopy != null) {
      pcCopy = pcCopy.deepCopy();
    }
    pojoResource.setPluginConfiguration(pcCopy);
    pojoResource.setName(resource.getName());
    pojoResource.setDescription(resource.getDescription());
    pojoResource.setLocation(resource.getLocation());
    pojoResource.setVersion(resource.getVersion());

    if (resource.getParentResource() != null) {
      pojoResource.setParentResource(convertToPojoResource(resource.getParentResource(), false));
    }
    if (includeDescendants) {
      for (Resource childResource : resource.getChildResources()) {
        if (isVisibleInInventory(childResource)) {
          pojoResource.addChildResource(convertToPojoResource(childResource, true));
        }
      }
    }
    return pojoResource;
  }
Ejemplo n.º 8
0
  /**
   * Tests that the JON Agent can be discovered.
   *
   * @throws Exception
   */
  public void testServerDiscovery() throws Exception {
    InventoryReport report = pc.getInventoryManager().executeServerScanImmediately();
    assert report != null;

    Resource platform = pc.getInventoryManager().getPlatform();
    Set<Resource> servers = platform.getChildResources();
    assert servers.size() > 0;

    Resource agent_resource = servers.iterator().next();
    assert agent_resource.getName().indexOf("RHQ Agent") > -1
        : "Bad name: " + agent_resource.getName();
    assert agent_resource.getResourceType().getName().equals(AGENT_RESOURCE_TYPE_NAME)
        : "Bad type: " + agent_resource.getResourceType();
    assert agent_resource.getResourceType().getCategory() == ResourceCategory.SERVER
        : "Bad type: " + agent_resource.getResourceType();

    pc.getInventoryManager().executeServiceScanImmediately();

    InventoryPrinter.outputInventory(new PrintWriter(System.out), false);
  }
Ejemplo n.º 9
0
  private Set<Resource> getDiscoveredServers() {
    Set<Resource> found = new HashSet<Resource>();
    Resource platform = PluginContainer.getInstance().getInventoryManager().getPlatform();
    for (Resource resource : platform.getChildResources()) {
      if (resource.getResourceType().getName().equals("Postgres Server")) {
        found.add(resource);
      }
    }

    return found;
  }
Ejemplo n.º 10
0
  private void buildFavoriteResourcesMenu(
      Favorites favorites,
      Menu menu,
      Set<Integer> resourceIds,
      AncestryUtil.MapWrapper typesWrapper) {

    if (resourceIds.isEmpty()) {
      menu.setItems();
      return;
    }

    List<MenuItem> items = new ArrayList<MenuItem>(resourceIds.size());

    for (final Integer resourceId : resourceIds) {
      Resource resource = favorites.getResource(resourceId);
      if (null == resource) {
        // if the resource is gone just skip it
        continue;
      }

      MenuItem item = new MenuItem(resource.getName());
      item.setIcon(ImageManager.getResourceIcon(resource));

      // build a subMenu to display a disambiguated resource
      item.setAttribute(AncestryUtil.RESOURCE_ID, resourceId);
      item.setAttribute(AncestryUtil.RESOURCE_NAME, resource.getName());
      item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY, resource.getAncestry());
      item.setAttribute(AncestryUtil.RESOURCE_TYPE_ID, resource.getResourceType().getId());
      item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES, typesWrapper);
      Menu ancestryMenu = new Menu();
      MenuItem ancestryItem = new MenuItem(AncestryUtil.getAncestryHoverHTML(item, -1));
      ancestryItem.setEnabled(false);
      ancestryMenu.setItems(ancestryItem);
      ancestryMenu.setSubmenuDirection("left");
      ancestryMenu.setAutoWidth();
      item.setSubmenu(ancestryMenu);

      item.addClickHandler(
          new com.smartgwt.client.widgets.menu.events.ClickHandler() {
            public void onClick(MenuItemClickEvent event) {
              CoreGUI.goToView(LinkManager.getResourceLink(resourceId));
            }
          });

      items.add(item);
    }

    menu.setCanSelectParentItems(Boolean.TRUE);
    menu.setItems(items.toArray(new MenuItem[items.size()]));
  }
Ejemplo n.º 11
0
  private List<Resource> findResources(
      Resource parent, String typeName, List<Resource> foundResources) {
    if (parent.getResourceType().getName().equals(typeName)) {
      foundResources.add(parent);
    }

    for (Resource resource : parent.getChildResources()) {
      for (Resource child : resource.getChildResources()) {
        findResources(child, typeName, foundResources);
      }
    }

    return foundResources;
  }
Ejemplo n.º 12
0
    /**
     * Additional processing to support a cross-resource view)
     *
     * @param result
     * @param response
     * @param request
     */
    protected void dataRetrieved(
        final PageList<AlertDefinition> result,
        final DSResponse response,
        final DSRequest request) {
      HashSet<Integer> typesSet = new HashSet<Integer>();
      HashSet<String> ancestries = new HashSet<String>();
      for (AlertDefinition alertDefinition : result) {
        Resource resource = alertDefinition.getResource();
        if (null != resource) {
          typesSet.add(resource.getResourceType().getId());
          ancestries.add(resource.getAncestry());
        }
      }

      // In addition to the types of the result resources, get the types of their ancestry
      typesSet.addAll(AncestryUtil.getAncestryTypeIds(ancestries));

      ResourceTypeRepository typeRepo = ResourceTypeRepository.Cache.getInstance();
      typeRepo.getResourceTypes(
          typesSet.toArray(new Integer[typesSet.size()]),
          new TypesLoadedCallback() {

            public void onTypesLoaded(Map<Integer, ResourceType> types) {
              // Smartgwt has issues storing a Map as a ListGridRecord attribute. Wrap it in a pojo.
              AncestryUtil.MapWrapper typesWrapper = new AncestryUtil.MapWrapper(types);

              Record[] records = buildRecords(result);
              for (Record record : records) {
                // To avoid a lot of unnecessary String construction, be lazy about building
                // ancestry hover text.
                // Store the types map off the records so we can build a detailed hover string as
                // needed.
                record.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES, typesWrapper);

                // Build the decoded ancestry Strings now for display
                record.setAttribute(
                    AncestryUtil.RESOURCE_ANCESTRY_VALUE, AncestryUtil.getAncestryValue(record));
              }
              response.setData(records);
              response.setTotalRows(
                  result
                      .getTotalSize()); // for paging to work we have to specify size of full result
              // set
              processResponse(request.getRequestId(), response);
            }
          });
    }
Ejemplo n.º 13
0
  private void deleteNewResource(Resource resource) throws Exception {
    if (null != resource) {
      EntityManager em = null;

      try {
        ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();

        // invoke bulk delete on the resource to remove any dependencies not defined in the
        // hibernate entity model
        // perform in-band and out-of-band work in quick succession
        List<Integer> deletedIds = resourceManager.uninventoryResource(overlord, resource.getId());
        for (Integer deletedResourceId : deletedIds) {
          resourceManager.uninventoryResourceAsyncWork(overlord, deletedResourceId);
        }

        // now dispose of other hibernate entities
        getTransactionManager().begin();
        em = getEntityManager();

        ResourceType type = em.find(ResourceType.class, resource.getResourceType().getId());
        Agent agent = em.find(Agent.class, resource.getAgent().getId());
        if (null != agent) {
          em.remove(agent);
        }
        if (null != type) {
          em.remove(type);
        }

        getTransactionManager().commit();
      } catch (Exception e) {
        try {
          System.out.println(
              "CANNOT CLEAN UP TEST (" + this.getClass().getSimpleName() + ") Cause: " + e);
          getTransactionManager().rollback();
        } catch (Exception ignore) {
        }
      } finally {
        if (null != em) {
          em.close();
        }
      }
    }
  }
Ejemplo n.º 14
0
  private void initContent() {
    ContentManagerRemote contentManager = remoteClient.getContentManager();
    List<PackageType> types = null;
    try {
      types =
          contentManager.findPackageTypes(
              remoteClient.getSubject(),
              resource.getResourceType().getName(),
              resource.getResourceType().getPlugin());

      for (PackageType packageType : types) {
        contentTypes.put(packageType.getName(), new ContentType(packageType));
      }
    } catch (ResourceTypeNotFoundException e) {
      LOG.error(
          "Could not find resource type while creating content mappings of the resource proxy for resource with id "
              + resourceId,
          e);
    }
  }
Ejemplo n.º 15
0
  private void initMeasurements() {
    MeasurementDefinitionCriteria criteria = new MeasurementDefinitionCriteria();
    criteria.addFilterResourceTypeId(resource.getResourceType().getId());
    //        criteria.addFilterResourceTypeName(resource.getResourceType().getName());
    //        criteria.setStrict(true);

    this.measurementDefinitions =
        remoteClient
            .getMeasurementDefinitionManager()
            .findMeasurementDefinitionsByCriteria(remoteClient.getSubject(), criteria);

    this.measurementMap = new HashMap<String, Measurement>();
    for (MeasurementDefinition def : measurementDefinitions) {
      Measurement m = new Measurement(def);

      String name = def.getDisplayName().replaceAll("\\W", "");
      name = decapitalize(name);

      this.measurementMap.put(name, m);
      this.allProperties.put(name, m);
    }
  }
  private void refreshSingletons(
      final Resource parentResource, final AsyncCallback<PageList<Resource>> callback) {
    singletonChildren = new ArrayList<Resource>(); // initialize to non-null

    Integer[] singletonChildTypes = getSingletonChildTypes(parentResource.getResourceType());

    if (canCreate && singletonChildTypes.length > 0 && (hasCreatableTypes || hasImportableTypes)) {
      ResourceCriteria criteria = new ResourceCriteria();
      criteria.addFilterParentResourceId(parentResource.getId());
      criteria.addFilterResourceTypeIds(singletonChildTypes);
      GWTServiceLookup.getResourceService()
          .findResourcesByCriteria(
              criteria,
              new AsyncCallback<PageList<Resource>>() {

                @Override
                public void onSuccess(PageList<Resource> result) {
                  singletonChildren = result;
                  if (callback != null) {
                    callback.onSuccess(result);
                  }
                }

                @Override
                public void onFailure(Throwable caught) {
                  Log.error("Failed to load child resources for [" + parentResource + "]", caught);
                  if (callback != null) {
                    callback.onFailure(caught);
                  }
                }
              });
    } else {
      if (callback != null) {
        callback.onSuccess(new PageList<Resource>());
      }
    }
  }
  private void removeExistingSingletons(
      List<Resource> singletonChildren, Map<String, ResourceType> displayNameMap) {

    List<String> existingSingletons = new ArrayList<String>();

    Set<String> displayNames = displayNameMap.keySet();
    for (final String displayName : displayNames) {
      final ResourceType type = displayNameMap.get(displayName);
      boolean exists = false;

      if (type.isSingleton()) {
        for (Resource child : singletonChildren) {
          exists = child.getResourceType().equals(displayNameMap.get(displayName));
          if (exists) {
            existingSingletons.add(displayName);
            break;
          }
        }
      }
    }
    for (String existing : existingSingletons) {
      displayNameMap.remove(existing);
    }
  }
 public ResourceType getResourceType() {
   return resource.getResourceType();
 }
Ejemplo n.º 19
0
  private void buildRecentlyViewedMenu(
      Favorites favorites,
      Menu menu,
      List<Integer> recentResourceIds,
      List<Integer> recentGroupIds,
      AncestryUtil.MapWrapper typesWrapper) {

    if (recentResourceIds.isEmpty() && recentGroupIds.isEmpty()) {
      return;
    }
    List<MenuItem> items =
        new ArrayList<MenuItem>(recentResourceIds.size() + recentGroupIds.size() + 1);

    for (final Integer resourceId : recentResourceIds) {
      Resource resource = favorites.getResource(resourceId);
      if (null == resource) {
        // if the resource is gone just skip it
        continue;
      }

      MenuItem item = new MenuItem(resource.getName());
      item.setIcon(ImageManager.getResourceIcon(resource));

      // build a subMenu to display a disambiguated resource
      item.setAttribute(AncestryUtil.RESOURCE_ID, resourceId);
      item.setAttribute(AncestryUtil.RESOURCE_NAME, resource.getName());
      item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY, resource.getAncestry());
      item.setAttribute(AncestryUtil.RESOURCE_TYPE_ID, resource.getResourceType().getId());
      item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES, typesWrapper);

      Menu ancestryMenu = new Menu();
      MenuItem ancestryItem = new MenuItem(AncestryUtil.getAncestryHoverHTML(item, -1));
      ancestryItem.setEnabled(false);
      ancestryMenu.setItems(ancestryItem);
      ancestryMenu.setSubmenuDirection("left");
      ancestryMenu.setAutoWidth();
      item.setSubmenu(ancestryMenu);

      item.addClickHandler(
          new com.smartgwt.client.widgets.menu.events.ClickHandler() {
            public void onClick(MenuItemClickEvent event) {
              CoreGUI.goToView(LinkManager.getResourceLink(resourceId));
            }
          });

      items.add(item);
    }

    if (!recentResourceIds.isEmpty() && !recentGroupIds.isEmpty()) {
      items.add(new MenuItemSeparator());
    }

    for (final Integer groupId : recentGroupIds) {
      ResourceGroupComposite groupComposite = favorites.getGroupComposite(groupId);
      if (null == groupComposite) {
        // if the resource group is gone just skip it
        continue;
      }
      final ResourceGroup group = groupComposite.getResourceGroup();

      MenuItem item = new MenuItem(String.valueOf(groupId));
      item.setTitle(group.getName());
      item.setIcon(
          ImageManager.getGroupIcon(
              group.getGroupCategory(), groupComposite.getExplicitAvailabilityType()));

      item.addClickHandler(
          new com.smartgwt.client.widgets.menu.events.ClickHandler() {
            public void onClick(MenuItemClickEvent event) {
              CoreGUI.goToView(LinkManager.getResourceGroupLink(group));
            }
          });
      items.add(item);
    }

    menu.setCanSelectParentItems(Boolean.TRUE);
    menu.setItems(items.toArray(new MenuItem[items.size()]));
  }
  private ResourceGroup createPlatformGroup(String groupName, Resource resource) {
    ResourceGroup group = new ResourceGroup(groupName, resource.getResourceType());
    group.addExplicitResource(resource);

    return resourceGroupManager.createResourceGroup(overlord, group);
  }
Ejemplo n.º 21
0
  /**
   * Given a deployment, this examines the destination and the resource to determine where exactly
   * the bundle distribution should be written.
   *
   * @param bundleResourceDeployment describes where the bundle should be or is deployed
   * @return absolute directory location where the bundle should be deployed
   */
  private File getAbsoluteDestinationDir(BundleResourceDeployment bundleResourceDeployment) {
    BundleDestination dest = bundleResourceDeployment.getBundleDeployment().getDestination();
    String destBaseDirName = dest.getDestinationBaseDirectoryName();
    String relativeDeployDir = dest.getDeployDir();

    // paranoia, if no deploy dir is given, as assume it will be directly under the base location
    if (relativeDeployDir == null || relativeDeployDir.trim().length() == 0) {
      relativeDeployDir = File.separator;
    }

    // get the resource entity stored in our local inventory
    InventoryManager im = getInventoryManager();
    Resource resource = bundleResourceDeployment.getResource();
    ResourceContainer container = im.getResourceContainer(resource);
    resource = container.getResource();

    // find out the type of base location that is specified by the bundle destination
    BundleDestinationBaseDirectory bundleDestBaseDir = null;
    ResourceTypeBundleConfiguration rtbc =
        resource.getResourceType().getResourceTypeBundleConfiguration();
    if (rtbc == null) {
      throw new IllegalArgumentException(
          "The resource type doesn't support bundle deployments: " + resource);
    }
    for (BundleDestinationBaseDirectory bdbd : rtbc.getBundleDestinationBaseDirectories()) {
      if (bdbd.getName().equals(destBaseDirName)) {
        bundleDestBaseDir = bdbd;
        break;
      }
    }
    if (bundleDestBaseDir == null) {
      throw new IllegalArgumentException(
          "The resource type doesn't support bundle destination base location named ["
              + destBaseDirName
              + "]");
    }

    // based on the type of destination base location, determine the root base directory
    String destBaseDirValueName =
        bundleDestBaseDir.getValueName(); // the name we look up in the given context
    String baseLocation;
    switch (bundleDestBaseDir.getValueContext()) {
      case fileSystem:
        {
          if (!new File(relativeDeployDir).isAbsolute()) {
            // the deploy dir is not absolute; since we need to pin it to something, we assume the
            // top root directory
            // unless the descriptor told us to go somewhere else differently
            baseLocation = destBaseDirValueName; // ultimately this came from the plugin descriptor
            if (baseLocation == null || baseLocation.trim().length() == 0) {
              baseLocation =
                  File
                      .separator; // paranoia, if the plugin descriptor didn't specify, assume the
                                  // top root directory
            }
          } else {
            baseLocation = null; // so the relativeDeployDir is processed as an absolute dir
          }
          break;
        }
      case pluginConfiguration:
        {
          baseLocation =
              resource.getPluginConfiguration().getSimpleValue(destBaseDirValueName, null);
          if (baseLocation == null) {
            throw new IllegalArgumentException(
                "Cannot determine the bundle base deployment location - "
                    + "there is no plugin configuration setting for ["
                    + destBaseDirValueName
                    + "]");
          }
          break;
        }
      case resourceConfiguration:
        {
          baseLocation =
              resource.getResourceConfiguration().getSimpleValue(destBaseDirValueName, null);
          if (baseLocation == null) {
            throw new IllegalArgumentException(
                "Cannot determine the bundle base deployment location - "
                    + "there is no resource configuration setting for ["
                    + destBaseDirValueName
                    + "]");
          }
          break;
        }
      case measurementTrait:
        {
          baseLocation = getMeasurementManager().getTraitValue(container, destBaseDirValueName);
          if (baseLocation == null) {
            throw new IllegalArgumentException(
                "Cannot obtain trait ["
                    + destBaseDirName
                    + "] for resource ["
                    + resource.getName()
                    + "]");
          }
          break;
        }
      default:
        {
          throw new IllegalArgumentException(
              "Unknown bundle destination location context: " + bundleDestBaseDir);
        }
    }

    File destDir = new File(baseLocation, relativeDeployDir);

    if (!destDir.isAbsolute()) {
      throw new IllegalArgumentException(
          "The base location path specified by ["
              + destBaseDirValueName
              + "] in the context ["
              + bundleDestBaseDir.getValueContext()
              + "] along with the destination directory of ["
              + relativeDeployDir
              + "] did not resolve to an absolute path ["
              + destDir.getPath()
              + "] so there is no way to know where to put the bundle.");
    }

    return destDir;
  }
Ejemplo n.º 22
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();
          }
        }
      }
    }
  }
Ejemplo n.º 23
0
 @Summary(index = 3)
 public ResourceType getResourceType() {
   return resource.getResourceType();
 }