Пример #1
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);
    }
  }
Пример #2
0
  /** Get a list of the individual 'child resources' of that autogroup. */
  private List<AutoGroupComposite> getAutoGroupChildren(
      Subject subject, int parentId, int resourceTypeId) {
    List<AutoGroupComposite> children = new ArrayList<AutoGroupComposite>();
    ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
    ResourceTypeManagerLocal resourceTypeMananger = LookupUtil.getResourceTypeManager();
    Resource parentResource = resourceManager.getResourceById(subject, parentId);
    ResourceType resourceType = null;
    try {
      resourceType = resourceTypeMananger.getResourceTypeById(subject, resourceTypeId);
    } catch (ResourceTypeNotFoundException e) {
      return children; // empty list if we don't know the child type
    }

    if ((resourceType != null) && (parentResource != null)) {

      // first get the resources in the autogroup
      List<ResourceWithAvailability> resourcesForAutoGroup =
          resourceManager.findResourcesByParentAndType(subject, parentResource, resourceType);

      int i = 0;
      int[] resourceIds = new int[resourcesForAutoGroup.size()];
      for (ResourceWithAvailability resourceInAutoGroup : resourcesForAutoGroup) {
        int id = resourceInAutoGroup.getResource().getId();
        resourceIds[i++] = id;
      }

      // And then the composite to return
      List<AutoGroupComposite> composites =
          resourceManager.findResourcesAutoGroups(subject, resourceIds);

      return composites;
    }

    return children; // empty
  }
Пример #3
0
  // @PostConstruct // when AS7-5530 is fixed, uncomment this and remove class
  // StartupBeanToWorkaroundAS7_5530
  @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
  public void init() throws RuntimeException {
    secureNaming();

    initialized = false;

    log.info("All business tier deployments are complete - finishing the startup...");

    // get singletons right now so we load the classes immediately into our classloader
    AlertConditionCacheCoordinator.getInstance();
    SessionManager.getInstance();
    AlertSerializer.getSingleton();
    AvailabilityReportSerializer.getSingleton();

    // load resource facets cache
    try {
      resourceTypeManager.reloadResourceFacetsCache();
    } catch (Throwable t) {
      log.error("Could not load ResourceFacets cache.", t);
    }

    // Before starting determine the operating mode of this server and
    // take any necessary initialization action. Must happen before comm startup since listeners
    // may be added.
    initializeServer();

    // The order here is important!!!
    // IF YOU WANT TO CHANGE THE ORDER YOU MUST GET THE CHANGE PEER-REVIEWED FIRST BEFORE COMMITTING
    // IT!!!
    //
    // If we start the scheduler before the comm layer, what happens if a stored job needs to send a
    // message?
    // But if we start the comm layer before the scheduler, what happens if a message is received
    // that needs
    // a job scheduled for it? I think the former is more likely to happen than the latter
    // (that is, a scheduled job would more likely need to send a message; as opposed to an incoming
    // message
    // causing a job to be scheduled), so that explains the ordering of the comm layer and the
    // scheduler.
    startHibernateStatistics();
    initScheduler(); // make sure this is initialized before starting the plugin deployer
    startPluginDeployer(); // make sure this is initialized before starting the server plugin
                           // container
    startServerPluginContainer(); // before comm in case an agent wants to talk to it
    installJaasModules();
    startServerCommunicationServices();
    startScheduler();
    scheduleJobs();
    // startAgentClients(); // this could be expensive if we have large number of agents so skip it
    // and we'll create them lazily
    // startEmbeddedAgent(); // this is obsolete - we no longer have an embedded agent
    registerShutdownListener();
    registerPluginDeploymentScannerJob();

    logServerStartedMessage();

    initialized = true;
    return;
  }
 private ResourceType loadResourceTypeFully(String typeName, String typePlugin) {
   ResourceTypeCriteria c = new ResourceTypeCriteria();
   c.addFilterName(typeName);
   c.addFilterPluginName(typePlugin);
   c.setStrict(true);
   c.fetchSubCategories(true);
   c.fetchPluginConfigurationDefinition(true);
   c.fetchProcessScans(true);
   c.fetchOperationDefinitions(true);
   c.fetchMetricDefinitions(true);
   c.fetchEventDefinitions(true);
   c.fetchResourceConfigurationDefinition(true);
   c.fetchDriftDefinitionTemplates(true);
   c.fetchBundleConfiguration(true);
   List<ResourceType> t = resourceTypeMgr.findResourceTypesByCriteria(subjectMgr.getOverlord(), c);
   ResourceType resourceType = t.get(0);
   return resourceType;
 }
  @BeforeMethod
  public void setupBeforeMethod() throws Exception {

    // Plugin service setup
    prepareScheduler();
    pluginService = new TestContentServerPluginService(this);

    TransactionManager tx = getTransactionManager();
    try {
      tx.begin();
      EntityManager entityManager = getEntityManager();

      ContentManagerLocal contentManager = LookupUtil.getContentManager();
      ContentSourceManagerLocal contentSourceManager = LookupUtil.getContentSourceManager();
      RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
      ResourceTypeManagerLocal resourceTypeManager = LookupUtil.getResourceTypeManager();
      SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
      Subject overlord = subjectManager.getOverlord();

      // protect if it aleady exists due to a failed run
      contentSourceType = contentSourceManager.getContentSourceType("testType");
      if (null == contentSourceType) {
        // Create a sample content source type that will be used in this test
        contentSourceType = new ContentSourceType("testType");
        entityManager.persist(contentSourceType);
        entityManager.flush();
      }

      // protect if it aleady exists due to a failed run
      ContentSource cs1 =
          contentSourceManager.getContentSourceByNameAndType(
              overlord, "contentSource1", "testType");
      if (null == cs1) {
        // A repo sync will query all providers for that repo, so add multiple providers
        cs1 = new ContentSource("contentSource1", contentSourceType);
        cs1.setDownloadMode(DownloadMode.DATABASE);
        cs1 = contentSourceManager.simpleCreateContentSource(overlord, cs1);
      }
      ContentSource cs2 =
          contentSourceManager.getContentSourceByNameAndType(
              overlord, "contentSource2", "testType");
      if (null == cs2) {
        cs2 = new ContentSource("contentSource2", contentSourceType);
        cs2.setDownloadMode(DownloadMode.DATABASE);
        cs2 = contentSourceManager.simpleCreateContentSource(overlord, cs2);
      }

      pluginService.associateContentProvider(cs1, contentProvider1);
      pluginService.associateContentProvider(cs2, contentProvider2);

      repoContentSources.add(cs1);
      repoContentSources.add(cs2);

      // Create the package type packages will be created against
      resourceType =
          resourceTypeManager.getResourceTypeByNameAndPlugin(
              TestContentProvider.RESOURCE_TYPE_NAME,
              TestContentProvider.RESOURCE_TYPE_PLUGIN_NAME);
      if (null == resourceType) {
        resourceType =
            new ResourceType(
                TestContentProvider.RESOURCE_TYPE_NAME,
                TestContentProvider.RESOURCE_TYPE_PLUGIN_NAME,
                ResourceCategory.PLATFORM,
                null);
        entityManager.persist(resourceType);
        entityManager.flush();
      }

      List<PackageType> packageTypes =
          contentManager.findPackageTypes(
              overlord,
              TestContentProvider.RESOURCE_TYPE_NAME,
              TestContentProvider.RESOURCE_TYPE_PLUGIN_NAME);
      if (!packageTypes.isEmpty()) {
        packageType = packageTypes.get(0);
      } else {
        packageType = new PackageType(TestContentProvider.PACKAGE_TYPE_NAME, resourceType);
        entityManager.persist(packageType);
      }

      // Create the repo to be synced
      List<Repo> repos = repoManager.getRepoByName(TestContentProvider.REPO_WITH_PACKAGES);
      if (!repos.isEmpty()) {
        repoToSync = repos.get(0);
      } else {
        Repo repo = new Repo(TestContentProvider.REPO_WITH_PACKAGES);
        repo.addContentSource(cs1);
        //        repo.addContentSource(cs2);  Disabled until we implement a second test content
        // source to return new stuff
        repoToSync = repoManager.createRepo(overlord, repo);
      }

      tx.commit();
    } catch (Throwable t) {
      tx.rollback();
      // rethrow because if we swallow the exception then tests proceed to execute when they
      // probably should not
      throw new RuntimeException(t);
    }
  }