Example #1
0
 private Set<String> enumerateIndexes(ProbeDescSummary summary) {
   MBeanServerConnection mbean = cnx.getConnection().connection;
   Set<String> indexes = new HashSet<String>();
   for (String name : summary.specifics.get("mbeanNames").split(" *; *")) {
     try {
       Set<ObjectName> mbeanNames = mbean.queryNames(new ObjectName(name), null);
       Pattern p = Pattern.compile(summary.specifics.get("mbeanIndex"));
       for (ObjectName oneMbean : mbeanNames) {
         log(Level.DEBUG, "%s", oneMbean.getCanonicalName());
         Matcher m = p.matcher(oneMbean.toString());
         if (m.matches() && !m.group(1).isEmpty()) {
           log(Level.DEBUG, "index found: %s for %s", m.group(1), summary.name);
           indexes.add(m.group(1));
         }
       }
     } catch (MalformedObjectNameException e) {
       log(
           Level.WARN,
           "invalid name for auto discovery of probe %s: %s",
           summary.name,
           e.getMessage());
     } catch (IOException e) {
       log(
           Level.WARN,
           "Connection failed for auto discovery of probe %s: %s",
           summary.name,
           e.getMessage());
     }
   }
   return indexes;
 }
Example #2
0
 @Override
 public boolean isGoodProbeDesc(ProbeDescSummary summary) {
   MBeanServerConnection mbean = cnx.getConnection().connection;
   boolean valid = true;
   boolean enumerated = false;
   for (String name : summary.specifics.get("mbeanNames").split(" *; *")) {
     enumerated = true;
     try {
       Set<ObjectName> mbeanNames = mbean.queryNames(new ObjectName(name), null);
       log(Level.TRACE, "%s", "found mbeans %s for %s", mbeanNames, summary.name);
       if (mbeanNames.size() > 1 && !summary.isIndexed) {
         log(Level.WARN, "not indexed probe %s return more than one mbean", summary.name);
         valid = false;
       } else if (mbeanNames.size() > 0) {
         valid &= true;
       } else {
         valid = false;
       }
     } catch (MalformedObjectNameException e) {
       log(
           Level.WARN,
           "invalid name for auto discovery of probe %s: %s",
           summary.name,
           e.getMessage());
     } catch (IOException e) {
       log(
           Level.WARN,
           "Connection failed for auto discovery of probe %s: %s",
           summary.name,
           e.getMessage());
     }
   }
   return valid && enumerated;
 }
Example #3
0
 static {
   try {
     service =
         new ObjectName(
             "com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
   } catch (MalformedObjectNameException e) {
     throw new AssertionError(e.getMessage());
   }
 }
  static boolean execScript(String process, String script) {
    int vmid = -1;
    try {
      vmid = Integer.parseInt(process);
    } catch (NumberFormatException e) {
      vmid = findVmid(process);
    }
    if (vmid == -1) {
      System.err.println(process + ": Could not find process");
      return false;
    }

    try {
      JMXConnector jmxc;
      MBeanServerConnection server;

      String address = ConnectorAddressLink.importFrom(vmid);
      JMXServiceURL jmxUrl = new JMXServiceURL(address);
      jmxc = JMXConnectorFactory.connect(jmxUrl);
      server = jmxc.getMBeanServerConnection();
      Object[] parameters = {script};
      String[] signature = {"java.lang.String"};
      Object result;
      result =
          server.invoke(
              new ObjectName("net.multiverse:type=Engine"),
              "runPythonScript",
              parameters,
              signature);
      System.out.println(result.toString());
      jmxc.close();
    } catch (IOException e) {
      System.err.println("Unable to attach to " + vmid + ": " + e.getMessage());
      return false;
    } catch (javax.management.MalformedObjectNameException e) {
      System.err.println("Internal error: " + e.getMessage());
      return false;
    } catch (javax.management.InstanceNotFoundException e) {
      System.err.println("Process " + vmid + " is not a Multiverse engine");
      return false;
    } catch (javax.management.MBeanException e) {
      System.err.println("Error: " + e);
      return false;
    } catch (javax.management.ReflectionException e) {
      System.err.println("Error: " + e);
      return false;
    }
    return true;
  }
  /**
   * Gets the initial file name.
   *
   * @param jvm The active JVM
   * @return The file name, or <tt>null</tt> if file name is specified
   * @throws JvmCoreException
   */
  String getInitialFileName(IActiveJvm jvm) throws JvmCoreException {

    ObjectName objectName;
    try {
      objectName = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
    } catch (MalformedObjectNameException e) {
      throw new JvmCoreException(IStatus.ERROR, e.getMessage(), e);
    } catch (NullPointerException e) {
      throw new JvmCoreException(IStatus.ERROR, e.getMessage(), e);
    }

    TabularData initialName =
        (TabularData)
            jvm.getMBeanServer().getAttribute(objectName, "SystemProperties"); // $NON-NLS-1$
    CompositeData compisiteData = initialName.get(new Object[] {"user.home"}); // $NON-NLS-1$
    String home = compisiteData.values().toArray(new String[0])[1];
    StringBuffer initialFileName = new StringBuffer(home);
    initialFileName
        .append(File.separator)
        .append(new Date().getTime())
        .append('.')
        .append(SnapshotType.Hprof.getExtension());
    return initialFileName.toString();
  }
  public CreateResourceReport createResource(CreateResourceReport report) {

    JBossASServerComponent parentResourceComponent =
        getResourceContext().getParentResourceComponent();

    String resourceTypeName = report.getResourceType().getName();

    String objectNamePreString;
    boolean isTopic = false;
    if (resourceTypeName.contains("Topic")) {
      objectNamePreString = TOPIC_MBEAN_NAME;
      isTopic = true;
    } else {
      objectNamePreString = QUEUE_MBEAN_NAME;
    }

    Configuration config = report.getResourceConfiguration();

    String name = config.getSimple("MBeanName").getStringValue();
    PropertySimple nameTemplateProp = report.getPluginConfiguration().getSimple("nameTemplate");
    String rName = nameTemplateProp.getStringValue();
    //noinspection ConstantConditions
    rName = rName.replace("{name}", name);

    EmsConnection connection = parentResourceComponent.getEmsConnection();

    if (DeploymentUtility.isDuplicateJndiName(connection, objectNamePreString, name)) {
      report.setStatus(CreateResourceStatus.FAILURE);
      report.setErrorMessage("Duplicate JNDI Name, a resource with that name already exists");
      return report;
    }
    PropertySimple pluginNameProperty = new PropertySimple("name", rName);
    getResourceContext().getPluginConfiguration().put(pluginNameProperty);

    File deployDir = new File(parentResourceComponent.getConfigurationPath() + "/deploy");
    File deploymentFile =
        new File(deployDir, FileNameUtility.formatFileName(name) + "-destination-service.xml");

    xmlEditor = new JBossMessagingConfigurationEditor(resourceTypeName);
    xmlEditor.updateConfiguration(deploymentFile, name, report);
    try {
      parentResourceComponent.deployFile(deploymentFile);
    } catch (Exception e) {
      JBossASServerComponent.setErrorOnCreateResourceReport(report, e.getLocalizedMessage(), e);
      return report;
    }

    // This key needs to be the same as the object name string used in discovery, defined in the
    // plugin descriptor
    //   jboss.messaging.destination:service=<Queue|Topic>,name=%name%
    String serviceString = (isTopic ? "Topic" : "Queue");

    String objectName = "jboss.messaging.destination:name=" + name + ",service=" + serviceString;
    try {
      // IMPORTANT: The object name must be canonicalized so it matches the resource key that
      //            MBeanResourceDiscoveryComponent uses, which is the canonical object name.
      objectName = getCanonicalName(objectName);
      report.setResourceKey(objectName);
    } catch (MalformedObjectNameException e) {
      log.warn("Invalid key [" + objectName + "]: " + e.getMessage());
      return report;
    }
    report.setResourceName(rName);

    try {
      Thread.sleep(5000L);
    } catch (InterruptedException e) {
      log.info("Sleep after datasource create interrupted", e);
      Thread.currentThread().interrupt();
    }

    return report;
  }
Example #7
0
  private void tryConnect(boolean requireRemoteSSL) throws IOException {
    if (jmxUrl == null && "localhost".equals(hostName) && port == 0) {
      // Monitor self
      this.jmxc = null;
      this.mbsc = ManagementFactory.getPlatformMBeanServer();
      this.server = Snapshot.newSnapshot(mbsc);
    } else {
      // Monitor another process
      if (lvm != null) {
        if (!lvm.isManageable()) {
          lvm.startManagementAgent();
          if (!lvm.isManageable()) {
            // FIXME: what to throw
            throw new IOException(lvm + "not manageable");
          }
        }
        if (this.jmxUrl == null) {
          this.jmxUrl = new JMXServiceURL(lvm.connectorAddress());
        }
      }
      Map<String, Object> env = new HashMap<String, Object>();
      if (requireRemoteSSL) {
        env.put("jmx.remote.x.check.stub", "true");
      }
      // Need to pass in credentials ?
      if (userName == null && password == null) {
        if (isVmConnector()) {
          // Check for SSL config on reconnection only
          if (stub == null) {
            checkSslConfig();
          }
          this.jmxc = new RMIConnector(stub, null);
          jmxc.connect(env);
        } else {
          this.jmxc = JMXConnectorFactory.connect(jmxUrl, env);
        }
      } else {
        env.put(JMXConnector.CREDENTIALS, new String[] {userName, password});
        if (isVmConnector()) {
          // Check for SSL config on reconnection only
          if (stub == null) {
            checkSslConfig();
          }
          this.jmxc = new RMIConnector(stub, null);
          jmxc.connect(env);
        } else {
          this.jmxc = JMXConnectorFactory.connect(jmxUrl, env);
        }
      }
      this.mbsc = jmxc.getMBeanServerConnection();
      this.server = Snapshot.newSnapshot(mbsc);
    }
    this.isDead = false;

    try {
      ObjectName on = new ObjectName(THREAD_MXBEAN_NAME);
      this.hasPlatformMXBeans = server.isRegistered(on);
      this.hasHotSpotDiagnosticMXBean =
          server.isRegistered(new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME));
      // check if it has 6.0 new APIs
      if (this.hasPlatformMXBeans) {
        MBeanOperationInfo[] mopis = server.getMBeanInfo(on).getOperations();
        // look for findDeadlockedThreads operations;
        for (MBeanOperationInfo op : mopis) {
          if (op.getName().equals("findDeadlockedThreads")) {
            this.supportsLockUsage = true;
            break;
          }
        }

        on = new ObjectName(COMPILATION_MXBEAN_NAME);
        this.hasCompilationMXBean = server.isRegistered(on);
      }
    } catch (MalformedObjectNameException e) {
      // should not reach here
      throw new InternalError(e.getMessage());
    } catch (IntrospectionException e) {
      InternalError ie = new InternalError(e.getMessage());
      ie.initCause(e);
      throw ie;
    } catch (InstanceNotFoundException e) {
      InternalError ie = new InternalError(e.getMessage());
      ie.initCause(e);
      throw ie;
    } catch (ReflectionException e) {
      InternalError ie = new InternalError(e.getMessage());
      ie.initCause(e);
      throw ie;
    }

    if (hasPlatformMXBeans) {
      // WORKAROUND for bug 5056632
      // Check if the access role is correct by getting a RuntimeMXBean
      getRuntimeMXBean();
    }
  }