Exemplo n.º 1
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;
    }
Exemplo n.º 2
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()]));
  }
Exemplo n.º 3
0
  protected void setResource(HttpServletRequest request, boolean config) throws Exception {
    try {
      Subject subject = WebUtility.getSubject(request);
      Integer resourceTypeId =
          WebUtility.getOptionalIntRequestParameter(
              request, ParamConstants.RESOURCE_TYPE_ID_PARAM, -1);
      int groupId = WebUtility.getOptionalIntRequestParameter(request, AttrConstants.GROUP_ID, -1);
      int parent = WebUtility.getOptionalIntRequestParameter(request, "parent", -1);
      String[] r = request.getParameterValues("r");
      String[] resourceIds = request.getParameterValues("resourceIds");

      // TODO rewrite the selection using WebUtility.getMetricsDisplayMode()
      if ((resourceTypeId > 0) && (parent > 0)) // autogroup
      {
        ResourceTypeManagerLocal resourceTypeManager = LookupUtil.getResourceTypeManager();
        ResourceType resourceType =
            resourceTypeManager.getResourceTypeById(subject, resourceTypeId);
        request.setAttribute(AttrConstants.RESOURCE_TYPE_ATTR, resourceType);
        request.setAttribute(AttrConstants.TITLE_PARAM_ATTR, resourceType.getName());
        request.setAttribute("parent", parent);
        request.setAttribute(ParamConstants.RESOURCE_TYPE_ID_PARAM, resourceTypeId);
        if (log.isDebugEnabled()) {
          log.debug("Autogroup p=" + parent + ", ct=" + resourceTypeId);
        }
      } else if (groupId > 0) // compat (or mixed) group
      {
        ResourceGroupManagerLocal resourceGroupManager = LookupUtil.getResourceGroupManager();
        ResourceGroup group = resourceGroupManager.getResourceGroupById(subject, groupId, null);
        request.setAttribute(AttrConstants.GROUP_ID, groupId);
        request.setAttribute(AttrConstants.TITLE_PARAM_ATTR, group.getName());
        // TODO more ?
      } else if ((resourceTypeId > 0) && (parent == -1)) // MeasurementDefinition
      {
        ResourceTypeManagerLocal resourceTypeManager = LookupUtil.getResourceTypeManager();
        ResourceType resourceType =
            resourceTypeManager.getResourceTypeById(subject, resourceTypeId);
        request.setAttribute(AttrConstants.RESOURCE_TYPE_ATTR, resourceType);
        request.setAttribute(ParamConstants.RESOURCE_TYPE_ID_PARAM, resourceTypeId);
      } else if ((r != null) && (r.length > 0)) // multiple scathered resources
      {
        log.trace("Multiple resources not handled yet"); // TODO what do we do here?
      } else if ((resourceIds != null) && (resourceIds.length > 0)) {
        log.trace("Multiple resources not yet handled"); // TODO what to we do here?
      } else // single resource
      {
        Integer resourceId =
            WebUtility.getRequiredIntRequestParameter(request, ParamConstants.RESOURCE_ID_PARAM);
        ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
        Resource resource = resourceManager.getResourceById(subject, resourceId);
        ResourceUIBean resourceUIBean = new ResourceUIBean(resource, subject);
        request.setAttribute(AttrConstants.RESOURCE_ATTR, resource);
        request.setAttribute(AttrConstants.RESOURCE_ID_ATTR, resourceId);
        request.setAttribute(AttrConstants.TITLE_PARAM_ATTR, resource.getName());
        request.setAttribute(
            AttrConstants.PERFORMANCE_SUPPORTED_ATTR, resourceUIBean.getFacets().isCallTime());
      }
    } catch (ResourceNotFoundException e) {
      RequestUtils.setError(request, MessageConstants.ERR_RESOURCE_NOT_FOUND);
    }
  }
  /**
   * Encode the beginning of the given {@link ResourceLineageComponent}.
   *
   * @param facesContext the JSF context for the current request
   * @param component the {@link ResourceLineageComponent} to be encoded
   */
  @Override
  public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
    ResourceLineageComponent resourceLineage = (ResourceLineageComponent) component;
    ResponseWriter writer = facesContext.getResponseWriter();
    long monitorId = HibernatePerformanceMonitor.get().start();
    ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
    List<Resource> ancestorResources =
        resourceManager.getResourceLineage(resourceLineage.getResourceId());
    HibernatePerformanceMonitor.get().stop(monitorId, "ResourceLineage renderer");
    if (ancestorResources.isEmpty()) {
      throw new IllegalStateException(
          "The list of ancestor resources should always contain at least one resource - the resource whose lineage was requested.");
    }

    Resource parentResource = ancestorResources.get(ancestorResources.size() - 1);
    for (Resource ancestorResource : ancestorResources) {
      writer.startElement("a", resourceLineage);
      writer.writeAttribute("href", buildURL(ancestorResource), null);
      writer.writeText(ancestorResource.getName(), null);
      writer.endElement("a");
      if (ancestorResource.getId()
          != parentResource.getId()) // separator after every item except the last one
      {
        writer.writeText(SEPARATOR, null);
      }
    }
  }
  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;
  }
Exemplo n.º 6
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);
  }
Exemplo n.º 7
0
  private Resource findServer(String name, Resource platform) {
    Set<Resource> servers = platform.getChildResources();

    for (Resource s : servers) {
      if (name.equals(s.getName())) {
        return s;
      }
    }

    return null;
  }
Exemplo n.º 8
0
 public String toString() {
   return "["
       + resourceId
       + "] "
       + resource.getName()
       + " ("
       + resource.getResourceType().getName()
       + "::"
       + resource.getResourceType().getPlugin()
       + ")";
 }
Exemplo n.º 9
0
  private Resource findService(String serviceName, String serverName, Resource platform) {
    Resource server = findServer(serverName, platform);

    if (server == null) {
      return null;
    }

    Set<Resource> services = server.getChildResources();

    for (Resource s : services) {
      if (serviceName.equals(s.getName())) {
        return s;
      }
    }

    return null;
  }
    private ResourceTreeNode(Resource resource) {
      this.resource = resource;

      String id = String.valueOf(resource.getId());
      String parentId =
          resource.getParentResource() == null
              ? null
              : String.valueOf((resource.getParentResource().getId()));

      setID(id);
      setParentID(parentId);

      setAttribute("id", id);
      setAttribute("parentId", parentId);
      setAttribute("name", resource.getName());
      setAttribute("timestamp", ""); // String.valueOf(resource.getItime())); // Seems to be null
      setAttribute(
          "currentAvailability",
          ImageManager.getAvailabilityIconFromAvailType(
              resource.getCurrentAvailability().getAvailabilityType()));
    }
Exemplo n.º 11
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()]));
  }
Exemplo n.º 12
0
 @Summary(index = 1)
 public String getName() {
   return resource.getName();
 }
Exemplo n.º 13
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;
  }