示例#1
0
  public boolean ClusterOrServerExists(
      DeployInfo deploInfo, AdminClient adminClient, ConfigService configService, Session session) {
    boolean exists = false;

    try {

      ObjectName ApplicationManager = null;
      ObjectName server1 =
          ConfigServiceHelper.createObjectName(null, "ApplicationServer", "server1");
      ObjectName[] matches = configService.queryConfigObjects(session, null, server1, null);
      //	         server1 = matches[0];   // use the first server found

      ObjectName Cluster = ConfigServiceHelper.createObjectName(null, "ServerCluster", "Test-CL");
      ObjectName[] Clusters = configService.queryConfigObjects(session, null, Cluster, null);

      ObjectName dataSource = ConfigServiceHelper.createObjectName(null, "DataSource");
      ObjectName[] dataSources = configService.queryConfigObjects(session, null, dataSource, null);

      Hashtable hs = dataSources[1].getKeyPropertyList();
      String[] keys = (String[]) hs.keySet().toArray(new String[0]);
      for (int i = 0; i < keys.length; i++) {
        System.out.println(keys[i].toString());
      }

      System.out.println(" Number if Clusters found " + Clusters.length);
      System.out.println(" Number if servers found " + matches.length);
      System.out.println(" Number if datasource found " + dataSources.length);

    } catch (ConnectorException e) {
      e.printStackTrace();
    } catch (ConfigServiceException e) {
      e.printStackTrace();
    }
    return exists;
  }
  /**
   * Method to get all the config objects that match resource given This method check if the find
   * should be done by containment path or find and resolve or if it should be done by attribute
   * name
   *
   * @param session
   * @param configService
   * @param resource
   * @param scope
   * @param inSyncMethod
   * @return
   * @throws ConnectorException
   * @throws ConfigServiceException
   * @throws AttributeNotFoundException
   * @throws MalformedObjectNameException
   */
  public ObjectName[] findAllResourcesInConfig(
      Session session,
      ConfigService configService,
      Resource resource,
      ObjectName scope,
      boolean inSyncMethod)
      throws ConnectorException, ConfigServiceException, AttributeNotFoundException {
    logger.debug(">>> find all resources " + resource.getContainmentPath());
    ResourceHelper resourceHelper = new ResourceHelper();

    ObjectName[] configIDs = null;
    String attributeNameForDuplicateObjectTypeChild = null;
    if (resource.getAttributeList().get(ResourceConstants.ATTRUBUTENAME) != null) {
      attributeNameForDuplicateObjectTypeChild =
          resource.getAttributeList().get(ResourceConstants.ATTRUBUTENAME).toString();
    }
    /**
     * SyncFindModeContainmentPath is used for objects like SIBusMemberTarget where there can be
     * only one bus SIBusMemberTarget under SIBusMember, so that we display only that.
     *
     * <p>But in the find mode we use the logic of
     */
    if (resource.getResourceMetaData().isSyncFindModeContainmentPath()) {
      logger.trace(
          " Get all ConfigObjects for the containment path "
              + resource.getContainmentPath()
              + " ] ");
      configIDs = configService.resolve(session, resource.getContainmentPath());
      // configIDs = resourceHelper.getObjectNames(session,configService,
      // resource.getContainmentPath());

    } else if ((!inSyncMethod) && (!resource.getResourceMetaData().isFindAndResolve())) {
      logger.trace(
          " Get all ConfigObjects using resourceHelper.getObjectNames "
              + resource.getName()
              + " to find "
              + resource
                  .getAttributeList()
                  .get(resource.getResourceMetaData().getContainmentAttribute()));
      configIDs =
          resourceHelper.getObjectNames(session, configService, resource.getContainmentPath());
    } else if (scope == null) {
      logger.trace(
          " Get all ConfigObjects for the type "
              + resource.getName()
              + " to find "
              + resource
                  .getAttributeList()
                  .get(resource.getResourceMetaData().getContainmentAttribute()));
      configIDs = configService.resolve(session, resource.getName());
    } else if (attributeNameForDuplicateObjectTypeChild != null) {
      logger.trace(
          " Get all ConfigObjects by getting  value of the attribute "
              + resource.getAttributeList().get(ResourceConstants.ATTRUBUTENAME)
              + " for resource "
              + resource.getName()
              + " to find "
              + resource
                  .getAttributeList()
                  .get(resource.getResourceMetaData().getContainmentAttribute()));
      ObjectName[] newConfigObject = {
        ConfigServiceHelper.createObjectName(
            (AttributeList)
                configService.getAttribute(
                    session,
                    resource.getParent().getConfigId(),
                    attributeNameForDuplicateObjectTypeChild))
      };
      configIDs = newConfigObject;
    } else {
      logger.trace(
          " Get ConfigObjects for the type "
              + resource.getName()
              + " in scope "
              + configService.getAttribute(session, scope, "name")
              + " to find "
              + resource
                  .getAttributeList()
                  .get(resource.getResourceMetaData().getContainmentAttribute()));
      configIDs = configService.resolve(session, scope, resource.getName());
    }

    // matchAdditionalContainmentAttributeIfRequired
    logger.debug("<<<  number of objects found" + configIDs.length);
    return configIDs;
  }