示例#1
0
  public int getSuffixNo(String newContainerPrefix) {
    int newContainerNo = 0;
    try {
      Service.Slice[] slices = getAllSlices();
      for (int i = 0; i < slices.length; i++) {
        LoadServiceSlice slice = (LoadServiceSlice) slices[i];
        String sliceName = slice.getNode().getName();
        if (sliceName.startsWith(newContainerPrefix)) {
          String endString = sliceName.replace(newContainerPrefix, "");
          try {
            Integer endNumber = Integer.parseInt(endString);
            if (endNumber > newContainerNo) {
              newContainerNo = endNumber;
            }

          } catch (Exception e) {
          }
        }
      }
    } catch (ServiceException errSlices) {
      logger.error(errSlices);
    }
    newContainerNo++;
    return newContainerNo;
  }
示例#2
0
  /**
   * Broadcast to start a new remote-container for this platform.
   *
   * @param containerName2Wait4 the container name2 wait4
   * @return the container2 wait4
   * @throws ServiceException the service exception
   */
  private Container2Wait4 broadcastGetNewContainer2Wait4Status(String containerName2Wait4)
      throws ServiceException {
    logger.debug("Start a new remote container!");

    String sliceName = null;
    try {
      LoadServiceSlice slice = (LoadServiceSlice) getSlice(MAIN_SLICE);
      sliceName = slice.getNode().getName();
      logger.debug("Try to start a new remote container " + sliceName);
      return slice.getNewContainer2Wait4Status(containerName2Wait4);
    } 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 starting a new remote-container from " + sliceName, t);
    }
    return null;
  }
示例#3
0
  /**
   * Broadcast the new locations to the agents.
   *
   * @see AID_Container
   * @param transferAgents the Vector of agents to transfer
   * @param slices the slices
   * @throws ServiceException the service exception
   */
  private void broadcastAgentMigration(Vector<AID_Container> transferAgents, Service.Slice[] slices)
      throws ServiceException {
    for (int i = 0; i < slices.length; i++) {
      String sliceName = null;
      try {
        LoadServiceSlice slice = (LoadServiceSlice) slices[i];
        sliceName = slice.getNode().getName();
        logger.info("Sending migration notification to agents at " + sliceName);

        slice.setAgentMigration(transferAgents);
      } 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 sending migration notification to agents at slice " + sliceName, t);
      }
    }
  }
示例#4
0
  /**
   * This Methods returns the default Remote-Container-Configuration, coming from the
   * Main-Container.
   *
   * @param preventUsageOfAlreadyUsedComputers the prevent usage of already used computers
   * @return the RemoteContainerConfig
   * @throws ServiceException the service exception
   */
  private RemoteContainerConfig broadcastGetAutoRemoteContainerConfig() throws ServiceException {

    logger.debug("Start request for the default remote container configuration!");
    String sliceName = null;
    try {
      LoadServiceSlice slice = (LoadServiceSlice) getSlice(MAIN_SLICE);
      sliceName = slice.getNode().getName();
      logger.debug(
          "Start request for the default remote container configuration at container " + sliceName);
      return slice.getAutoRemoteContainerConfig();
    } 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 the default remote container configuration from " + sliceName,
          t);
    }
    return null;
  }
示例#5
0
  /**
   * Broadcast to set the defaults for a remote container configuration.
   *
   * @param remoteContainerConfig the remote container configuration
   * @throws ServiceException the service exception
   */
  private void broadcastSetDefaults4RemoteContainerConfig(
      RemoteContainerConfig remoteContainerConfig) throws ServiceException {
    logger.debug("Sending the default remote container configuration!");

    String sliceName = null;
    try {
      LoadServiceSlice slice = (LoadServiceSlice) getSlice(MAIN_SLICE);
      sliceName = slice.getNode().getName();
      logger.debug("Sending the default remote container configuration to container " + sliceName);
      slice.setDefaults4RemoteContainerConfig(remoteContainerConfig);
    } 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 try to send the default remote container configuration to container "
              + sliceName,
          t);
    }
  }
示例#6
0
  /**
   * 'Broadcast' (or receive) all Informations about the containers load. The information will be
   * set to the local {@link #loadInfo}.
   *
   * @param slices the slices
   * @throws ServiceException the service exception
   */
  private void broadcastMeasureLoad(Service.Slice[] slices) throws ServiceException {

    loadInfo.containerLoads.clear();
    logger.debug("Try to get Load-Information 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 Load-Information of " + sliceName);
        PlatformLoad pl = slice.measureLoad();
        loadInfo.containerLoads.put(sliceName, pl);
      } 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 executing 'MeasureLoad' on slice " + sliceName, t);
      }
    }
  }
示例#7
0
  /**
   * Broadcast informtion's of the remote-container (OS etc.) to all remote-container of this
   * platform.
   *
   * @param slices the slices
   * @param crcReply the ClientRemoteContainerReply
   * @throws ServiceException the service exception
   */
  private void broadcastPutContainerDescription(
      Service.Slice[] slices, ClientRemoteContainerReply crcReply) throws ServiceException {

    logger.debug("Sending remote container Information!");

    for (int i = 0; i < slices.length; i++) {
      String sliceName = null;
      try {
        LoadServiceSlice slice = (LoadServiceSlice) slices[i];
        sliceName = slice.getNode().getName();
        logger.debug("Try sending remote container Information to " + sliceName);

        slice.putContainerDescription(crcReply);
      } 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 try to send container information to " + sliceName, t);
      }
    }
  }
示例#8
0
  /**
   * Collects all {@link Location} information from the connected container. The information will be
   * set to the local {@link #loadInfo}.
   *
   * @param slices the slices
   * @throws ServiceException the service exception
   */
  private void broadcastGetContainerLocation(Service.Slice[] slices) throws ServiceException {

    loadInfo.containerLocations.clear();
    logger.debug("Try to get Location-Informations!");

    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 Location-Object for " + sliceName);
        Location cLoc = slice.getLocation();
        loadInfo.containerLocations.put(sliceName, cLoc);
      } 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 try to get Location-Object from " + sliceName, t);
      }
    }
  }
示例#9
0
  /**
   * This method starts an agent on an designate (remote) container.
   *
   * @param localName4Agent the nick local Name of the agent
   * @param agentClassName the agent class name
   * @param args the args
   * @param containerName the container name
   * @return true, if successful
   * @throws ServiceException the service exception
   */
  private boolean broadcastStartAgent(
      String localName4Agent, String agentClassName, Object[] args, String containerName)
      throws ServiceException {
    logger.info("Try to start agent " + localName4Agent + " on container" + containerName);
    String sliceName = null;
    try {
      LoadServiceSlice slice = (LoadServiceSlice) getSlice(containerName);
      sliceName = slice.getNode().getName();
      logger.info("Start agent '" + localName4Agent + "' on container " + sliceName + "");

      return slice.startAgent(localName4Agent, agentClassName, args);
    } 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 the default remote container configuration from " + sliceName,
          t);
    }
    return false;
  }
示例#10
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);
      }
    }
  }
示例#11
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);
      }
    }
  }
示例#12
0
  /**
   * Broadcast the set of threshold levels to all container.
   *
   * @param slices the slices
   * @param thresholdLevels the threshold levels
   * @throws ServiceException the service exception
   */
  private void broadcastThresholdLevels(Service.Slice[] slices, LoadThresholdLevels thresholdLevels)
      throws ServiceException {

    loadInfo.containerLoads.clear();
    logger.debug("Try to set threshold level to 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 set threshold level to " + sliceName);

        slice.setThresholdLevels(thresholdLevels);
      } 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 try to set threshold level to slice " + sliceName, t);
      }
    }
  }
示例#13
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();
  }