Example #1
0
  /**
   * This method configures and send a ACLMessage to start a new remote-Container.
   *
   * @param remConf the RemoteContainerConfig
   * @param preventUsageOfAlreadyUsedComputers the boolean prevent usage of already used computers
   * @return the name of the container
   */
  private String sendMsgRemoteContainerRequest(RemoteContainerConfig inConf) {

    // --- Get the local Address of JADE ------------------------
    String myPlatformAddress = myContainer.getPlatformID();

    // --- If the remote-configuration is null configure it now -
    RemoteContainerConfig remConf = this.getRemoteContainerConfigAuto();
    if (inConf != null) {
      if (inConf.getJadeContainerName() != null) {
        String name = inConf.getJadeContainerName();
        int suf = getSuffixNo(inConf.getJadeContainerName());
        name = name + suf;
        remConf.setJadeContainerName(name);
      }
      if (inConf.getJadeHost() != null) {
        remConf.setJadeHost(inConf.getJadeHost());
      }
      if (inConf.getJadePort() != null) {
        remConf.setJadePort(inConf.getJadePort());
      }
      if (inConf.getJadeServices() != null) {
        remConf.setJadeServices(inConf.getJadeServices());
      }
    }

    // --- Define the AgentAction -------------------------------
    ClientRemoteContainerRequest req = new ClientRemoteContainerRequest();
    req.setRemoteConfig(remConf);

    Action act = new Action();
    act.setActor(myContainer.getAMS());
    act.setAction(req);

    // --- Define receiver of the Message -----------------------
    AID agentGUIAgent = new AID("server.client" + "@" + myPlatformAddress, AID.ISGUID);

    // --- Build Message ----------------------------------------
    ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
    msg.setSender(myContainer.getAMS());
    msg.addReceiver(agentGUIAgent);
    msg.setLanguage(new SLCodec().getName());
    msg.setOntology(DistributionOntology.getInstance().getName());
    try {
      msg.setContentObject(act);
    } catch (IOException errCont) {
      logger.error(errCont);
    }

    // --- Send message -----------------------------------------
    myContainer.postMessageToLocalAgent(msg, agentGUIAgent);

    // --- Remind, that we're waiting for this container --------
    loadInfo.setNewContainer2Wait4(remConf.getJadeContainerName());

    // --- Return -----------------------------------------------
    return remConf.getJadeContainerName();
  }
Example #2
0
  /**
   * 'Broadcast' (or receive) the list of all agents in a container. The information will be set to
   * the local {@link #loadInfo}.
   *
   * @param slices the slices
   * @throws ServiceException the service exception
   */
  private void broadcastGetAIDList(Service.Slice[] slices) throws ServiceException {

    loadInfo.resetAIDs4Container();
    logger.debug("Try to get AID's from all Containers !");

    for (int i = 0; i < slices.length; i++) {
      String sliceName = null;
      try {
        LoadServiceSlice slice = (LoadServiceSlice) slices[i];
        sliceName = slice.getNode().getName();
        logger.debug("Try to get AID''s from " + sliceName);

        AID[] aid = slice.getAIDList();
        loadInfo.putAIDs4Container(sliceName, aid);
      } catch (ServiceException | IMTPException t) {
        // NOTE that slices are always retrieved from the main and not from the cache --> No need to
        // retry in case of failure
        logger.warn("Error while trying to get AID's from " + sliceName, t);
      }
    }

    loadInfo.countAIDs4Container();
  }
Example #3
0
  /**
   * If the new slice is a LoadServiceSlice notify it about the current state.
   *
   * @param cmd the VerticalCommand
   */
  private void handleNewSlice(VerticalCommand cmd) {

    if (cmd.getService().equals(NAME)) {
      // --- We ARE in the Main-Container !!! ----------------------------------------
      Object[] params = cmd.getParams();
      String newSliceName = (String) params[0];
      try {
        // --- Is this the slice, we have waited for? ------------------------------
        loadInfo.setNewContainerStarted(newSliceName);
        // --- Be sure to get the new (fresh) slice --> Bypass the service cache ---
        LoadServiceSlice newSlice = (LoadServiceSlice) getFreshSlice(newSliceName);
        // --- Set the local ThresholdLevels to the new container ------------------
        newSlice.setThresholdLevels(LoadMeasureThread.getThresholdLevels());

      } catch (ServiceException | IMTPException t) {
        logger.error(
            "Error notifying new slice " + newSliceName + " about current LoadService-State", t);
      }
    }
  }
Example #4
0
  /**
   * 'Broadcast' (or receive) the list of all agents in a container with a registered sensor. The
   * information will be set to the local {@link #loadInfo}.
   *
   * @param slices the slices
   * @throws ServiceException the service exception
   */
  private void broadcastGetAIDListSensorAgents(Service.Slice[] slices) throws ServiceException {

    loadInfo.sensorAgents = new Vector<>();
    logger.debug("Try to get Sensor-AID's from all Containers !");

    for (int i = 0; i < slices.length; i++) {
      String sliceName = null;
      try {
        LoadServiceSlice slice = (LoadServiceSlice) slices[i];
        sliceName = slice.getNode().getName();
        logger.debug("Try to get Sensor-AID''s from " + sliceName);

        AID[] aidList = slice.getAIDListSensorAgents();
        loadInfo.sensorAgents.addAll(new Vector<>(Arrays.asList(aidList)));
      } catch (ServiceException | IMTPException t) {
        // NOTE that slices are always retrieved from the main and not from the cache --> No need to
        // retry in case of failure
        logger.warn("Error while trying to get Sensor-AID's from " + sliceName, t);
      }
    }
  }