Esempio n. 1
0
  /** This is the default constructor. */
  public JEEMonitor() {

    try {
      InitialContext ctx = new InitialContext();

      _acmManager = (ActiveCollectionManager) ctx.lookup(ACM_MANAGER);

      _responseTimesProcessed =
          (ActiveList) _acmManager.getActiveCollection(RESPONSE_TIMES_PROCESSED);
      _responseTimesProcessed.addActiveChangeListener(this);

    } catch (Exception e) {
      LOG.log(Level.SEVERE, "Failed to initialize active collection manager", e);
    }
  }
  /**
   * This method handles queries.
   *
   * @param width The optional width
   * @return The list of objects
   * @throws Exception Failed to query
   */
  @GET
  @Path("/overview")
  @Produces("image/svg+xml")
  public String overview(@DefaultValue("0") @QueryParam("width") int width) throws Exception {
    String ret = "";

    // Obtain service definition collection
    if (_acmManager != null && _servDefns == null) {
      _servDefns = _acmManager.getActiveCollection("ServiceDefinitions");
    }

    if (_acmManager != null && _situations == null) {
      _situations = _acmManager.getActiveCollection("Situations");
    }

    if (_servDefns == null) {
      throw new Exception("Service definitions are not available");
    }

    if (_situations == null) {
      throw new Exception("Situations are not available");
    }

    java.util.Set<ServiceDefinition> sds = new java.util.HashSet<ServiceDefinition>();

    for (Object entry : _servDefns) {
      if (entry instanceof ActiveMap.Entry
          && ((ActiveMap.Entry) entry).getValue() instanceof ServiceDefinition) {
        sds.add((ServiceDefinition) ((ActiveMap.Entry) entry).getValue());
      }
    }

    java.util.List<Situation> situations = new java.util.ArrayList<Situation>();

    for (Object obj : _situations) {
      if (obj instanceof Situation) {
        situations.add((Situation) obj);
      }
    }

    ServiceGraph graph = ServiceDependencyBuilder.buildGraph(sds, situations);

    if (graph == null) {
      throw new Exception("Failed to generate service dependency overview");
    }

    graph.setDescription("Generated: " + new java.util.Date());

    ServiceGraphLayoutImpl layout = new ServiceGraphLayoutImpl();

    layout.layout(graph);

    // Check some of the dimensions
    SVGServiceGraphGenerator generator = new SVGServiceGraphGenerator();

    MVELColorSelector selector = new MVELColorSelector();

    selector.setScriptLocation("ColorSelector.mvel");

    try {
      selector.init();
      generator.setColorSelector(selector);
    } catch (Exception e) {
      LOG.log(
          Level.SEVERE,
          java.util.PropertyResourceBundle.getBundle("service-dependency-rests.Messages")
              .getString("SERVICE-DEPENDENCY-RESTS-2"),
          e);
    }

    java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream();

    generator.generate(graph, width, os);

    os.close();

    ret = new String(os.toByteArray());

    if (LOG.isLoggable(Level.FINEST)) {
      LOG.finest("Overview=" + ret);
    }

    return (ret);
  }