Esempio n. 1
0
    /** {@inheritDoc} */
    @Override
    protected Collection<GridComputeJobAdapter> split(int gridSize, Object arg)
        throws GridException {
      assert rsrc1 != null;
      assert rsrc2 != null;
      assert rsrc3 != null;
      assert rsrc4 != null;
      assert log != null;

      log.info("Injected shared resource1 into task: " + rsrc1);
      log.info("Injected shared resource2 into task: " + rsrc2);
      log.info("Injected shared resource3 into task: " + rsrc3);
      log.info("Injected shared resource4 into task: " + rsrc4);
      log.info("Injected log resource into task: " + log);

      task1Rsrc1 = rsrc1;
      task1Rsrc2 = rsrc2;
      task1Rsrc3 = rsrc3;
      task1Rsrc4 = rsrc4;

      Collection<GridComputeJobAdapter> jobs = new ArrayList<>(gridSize);

      for (int i = 0; i < gridSize; i++) {
        jobs.add(new GridSharedJob1());
      }

      return jobs;
    }
  /**
   * Change topology.
   *
   * @param parent Grid to execute tasks on.
   * @param add New nodes count.
   * @param rmv Remove nodes count.
   * @param type Type of nodes to manipulate.
   */
  private static void changeTopology(Ignite parent, int add, int rmv, String type) {
    Collection<ComputeTaskFuture<?>> tasks = new ArrayList<>();

    IgniteCompute comp = parent.compute().withAsync();

    // Start nodes in parallel.
    while (add-- > 0) {
      comp.execute(ClientStartNodeTask.class, type);

      tasks.add(comp.future());
    }

    for (ComputeTaskFuture<?> task : tasks) task.get();

    // Stop nodes in sequence.
    while (rmv-- > 0) parent.compute().execute(ClientStopNodeTask.class, type);

    // Wait for node stops.
    // U.sleep(1000);

    Collection<String> gridNames = new ArrayList<>();

    for (Ignite g : G.allGrids()) gridNames.add(g.name());

    parent.log().info(">>> Available grids: " + gridNames);
  }
  /** @throws Exception If failed. */
  public void testNames() throws Exception {
    assertEquals("value1", svc.cacheable(1));

    Collection<String> names = mgr.getCacheNames();

    assertEquals(names.toString(), 2, names.size());
  }
Esempio n. 4
0
    /** {@inheritDoc} */
    @Override
    protected Collection<GridComputeJobAdapter> split(int gridSize, Object arg)
        throws GridException {
      assert rsrc1 != null;
      assert rsrc2 != null;
      assert rsrc3 != null;
      assert rsrc4 != null;
      assert log != null;

      log.info("Injected shared resource1 into task: " + rsrc1);
      log.info("Injected shared resource2 into task: " + rsrc2);
      log.info("Injected shared resource3 into task: " + rsrc3);
      log.info("Injected shared resource4 into task: " + rsrc4);
      log.info("Injected log resource into task: " + log);

      task2Rsrc1 = rsrc1;
      task2Rsrc2 = rsrc2;
      task2Rsrc3 = rsrc3;
      task2Rsrc4 = rsrc4;

      Collection<GridComputeJobAdapter> jobs = new ArrayList<>(gridSize);

      for (int i = 0; i < gridSize; i++) {
        jobs.add(
            new GridComputeJobAdapter() {
              /** User resource. */
              @GridUserResource(resourceClass = UserResource1.class)
              private transient GridAbstractUserResource rsrc5;

              /** User resource */
              @GridUserResource private transient UserResource2 rsrc6;

              /** User resource. */
              @GridUserResource(resourceClass = UserResource1.class, resourceName = "rsrc3")
              private transient GridAbstractUserResource rsrc7;

              /** User resource */
              @GridUserResource(resourceName = "rsrc4")
              private transient UserResource2 rsrc8;

              /** {@inheritDoc} */
              @SuppressWarnings({"ObjectEquality"})
              @Override
              public Serializable execute() {
                assert rsrc1 != null;
                assert rsrc2 != null;
                assert rsrc3 != null;
                assert rsrc4 != null;
                assert log != null;

                assert rsrc5 != null;
                assert rsrc6 != null;
                assert rsrc7 != null;
                assert rsrc8 != null;

                // Make sure that neither task nor global scope got
                // created more than once.
                assert rsrc1 == rsrc5;
                assert rsrc2 == rsrc6;
                assert rsrc3 == rsrc7;
                assert rsrc4 == rsrc8;

                log.info("Injected shared resource1 into job: " + rsrc1);
                log.info("Injected shared resource2 into job: " + rsrc2);
                log.info("Injected shared resource3 into job: " + rsrc3);
                log.info("Injected shared resource4 into job: " + rsrc4);
                log.info("Injected shared resource5 into job: " + rsrc5);
                log.info("Injected shared resource6 into job: " + rsrc6);
                log.info("Injected shared resource7 into job: " + rsrc7);
                log.info("Injected shared resource8 into job: " + rsrc8);
                log.info("Injected log resource into job: " + log);

                return null;
              }
            });
      }

      return jobs;
    }
  /**
   * See <a href="http://e-docs.bea.com/wls/docs100/javadocs/weblogic/common/T3StartupDef.html">
   * http://e-docs.bea.com/wls/docs100/javadocs/weblogic/common/T3StartupDef.html</a> for more
   * information.
   *
   * @param str Virtual name by which the class is registered as a {@code startupClass} in the
   *     {@code config.xml} file
   * @param params A hashtable that is made up of the name-value pairs supplied from the {@code
   *     startupArgs} property
   * @return Result string (log message).
   * @throws Exception Thrown if error occurred.
   */
  @SuppressWarnings({"unchecked", "CatchGenericClass"})
  @Override
  public String startup(String str, Hashtable params) throws Exception {
    GridLogger log = new GridJavaLogger(LoggingHelper.getServerLogger());

    cfgFile = (String) params.get(cfgFilePathParam);

    if (cfgFile == null) {
      throw new IllegalArgumentException("Failed to read property: " + cfgFilePathParam);
    }

    String workMgrName = (String) params.get(workMgrParam);

    URL cfgUrl = U.resolveGridGainUrl(cfgFile);

    if (cfgUrl == null)
      throw new ServerLifecycleException(
          "Failed to find Spring configuration file (path provided should be "
              + "either absolute, relative to GRIDGAIN_HOME, or relative to META-INF folder): "
              + cfgFile);

    GenericApplicationContext springCtx;

    try {
      springCtx = new GenericApplicationContext();

      XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(springCtx);

      xmlReader.loadBeanDefinitions(new UrlResource(cfgUrl));

      springCtx.refresh();
    } catch (BeansException e) {
      throw new ServerLifecycleException(
          "Failed to instantiate Spring XML application context: " + e.getMessage(), e);
    }

    Map cfgMap;

    try {
      // Note: Spring is not generics-friendly.
      cfgMap = springCtx.getBeansOfType(GridConfiguration.class);
    } catch (BeansException e) {
      throw new ServerLifecycleException(
          "Failed to instantiate bean [type="
              + GridConfiguration.class
              + ", err="
              + e.getMessage()
              + ']',
          e);
    }

    if (cfgMap == null)
      throw new ServerLifecycleException(
          "Failed to find a single grid factory configuration in: " + cfgUrl);

    if (cfgMap.isEmpty())
      throw new ServerLifecycleException("Can't find grid factory configuration in: " + cfgUrl);

    try {
      ExecutorService execSvc = null;

      MBeanServer mbeanSrv = null;

      for (GridConfiguration cfg : (Collection<GridConfiguration>) cfgMap.values()) {
        assert cfg != null;

        GridConfigurationAdapter adapter = new GridConfigurationAdapter(cfg);

        // Set logger.
        if (cfg.getGridLogger() == null) adapter.setGridLogger(log);

        if (cfg.getExecutorService() == null) {
          if (execSvc == null)
            execSvc =
                workMgrName != null
                    ? new GridThreadWorkManagerExecutor(workMgrName)
                    : new GridThreadWorkManagerExecutor(J2EEWorkManager.getDefault());

          adapter.setExecutorService(execSvc);
        }

        if (cfg.getMBeanServer() == null) {
          if (mbeanSrv == null) {
            InitialContext ctx = null;

            try {
              ctx = new InitialContext();

              mbeanSrv = (MBeanServer) ctx.lookup("java:comp/jmx/runtime");
            } catch (Exception e) {
              throw new IllegalArgumentException(
                  "MBean server was not provided and failed to obtain " + "Weblogic MBean server.",
                  e);
            } finally {
              if (ctx != null) ctx.close();
            }
          }

          adapter.setMBeanServer(mbeanSrv);
        }

        Grid grid = G.start(adapter, springCtx);

        // Test if grid is not null - started properly.
        if (grid != null) gridNames.add(grid.name());
      }

      return getClass().getSimpleName() + " started successfully.";
    } catch (GridException e) {
      // Stop started grids only.
      for (String name : gridNames) G.stop(name, true);

      throw new ServerLifecycleException("Failed to start GridGain.", e);
    }
  }