Package com.dotcms.enterprise.cluster.action.model

Examples of com.dotcms.enterprise.cluster.action.model.ServerActionBean


            //If we are removing a remote Server we need to create a ServerAction.
            if(UtilMethods.isSet(remoteServerId) && !remoteServerId.equals("undefined")){
              ResetLicenseServerAction resetLicenseServerAction = new ResetLicenseServerAction();
              Long timeoutSeconds = new Long(1);
             
              ServerActionBean resetLicenseServerActionBean =
                  resetLicenseServerAction.getNewServerAction(localServerId, remoteServerId, timeoutSeconds);
             
              resetLicenseServerActionBean = APILocator.getServerActionAPI()
                  .saveServerActionBean(resetLicenseServerActionBean);
             
              //Waits for 3 seconds in order all the servers respond.
          int maxWaitTime =
              timeoutSeconds.intValue() * 1000 + Config.getIntProperty("CLUSTER_SERVER_THREAD_SLEEP", 2000) ;
          int passedWaitTime = 0;
         
          //Trying to NOT wait whole 3 secons for returning the info.
          while (passedWaitTime <= maxWaitTime){
            try {
                Thread.sleep(10);
                passedWaitTime += 10;
               
                resetLicenseServerActionBean =
                    APILocator.getServerActionAPI().findServerActionBean(resetLicenseServerActionBean.getId());
               
                //No need to wait if we have all Action results.
                if(resetLicenseServerActionBean != null && resetLicenseServerActionBean.isCompleted()){
                  passedWaitTime = maxWaitTime + 1;
                }
               
            } catch(InterruptedException ex) {
                Thread.currentThread().interrupt();
                passedWaitTime = maxWaitTime + 1;
            }
          }
         
          //If we reach the timeout and the server didn't respond.
          //We assume the server is down and remove the license from the table.
          if(!resetLicenseServerActionBean.isCompleted()){
           
            resetLicenseServerActionBean.setCompleted(true);
            resetLicenseServerActionBean.setFailed(true);
            resetLicenseServerActionBean
              .setResponse(new com.dotmarketing.util.json.JSONObject()
              .put(ServerAction.ERROR_STATE, "Server did NOT respond on time"));
            APILocator.getServerActionAPI().saveServerActionBean(resetLicenseServerActionBean);
            LicenseUtil.freeLicenseOnRepo(serial);
         
          //If it was completed but we got some error, we need to alert it.
          } else if(resetLicenseServerActionBean.isCompleted()
              && resetLicenseServerActionBean.isFailed()){
           
            throw new Exception(resetLicenseServerActionBean.getResponse().getString(ServerAction.ERROR_STATE));
          }
             
            //If the server we are removing license is local.
            } else {
              HibernateUtil.startTransaction();
View Full Code Here


        NodeStatusServerAction nodeStatusServerAction = new NodeStatusServerAction();
        Long timeoutSeconds = new Long(1);
   
    for (Server server : servers) {
     
      ServerActionBean nodeStatusServerActionBean =
          nodeStatusServerAction.getNewServerAction(myServerId, server.getServerId(), timeoutSeconds);
     
      nodeStatusServerActionBean =
          APILocator.getServerActionAPI().saveServerActionBean(nodeStatusServerActionBean);
     
      actionBeans.add(nodeStatusServerActionBean);
    }
   
    //Waits for 3 seconds in order server respond.
    int maxWaitTime =
        timeoutSeconds.intValue() * 1000 + Config.getIntProperty("CLUSTER_SERVER_THREAD_SLEEP", 2000) ;
    int passedWaitTime = 0;
   
    //Trying to NOT wait whole time for returning the info.
    while (passedWaitTime <= maxWaitTime){
      try {
          Thread.sleep(10);
          passedWaitTime += 10;
         
          resultActionBeans = new ArrayList<ServerActionBean>();
         
          //Iterates over the Actions in order to see if we have it all.
          for (ServerActionBean actionBean : actionBeans) {
            ServerActionBean resultActionBean =
                APILocator.getServerActionAPI().findServerActionBean(actionBean.getId());
           
            //Add the ActionBean to the list of results.
            if(resultActionBean.isCompleted()){
              resultActionBeans.add(resultActionBean);
            }
        }
         
          //No need to wait if we have all Action results.
          if(resultActionBeans.size() == servers.size()){
            passedWaitTime = maxWaitTime + 1;
          }
         
      } catch(InterruptedException ex) {
          Thread.currentThread().interrupt();
          passedWaitTime = maxWaitTime + 1;
      }
    }
   
    //If some of the server didn't pick up the action, means they are down.
    if(resultActionBeans.size() != actionBeans.size()){
      //Need to find out which is missing?
      for(ServerActionBean actionBean : actionBeans){
        boolean isMissing = true;
        for(ServerActionBean resultActionBean : resultActionBeans){
          if(resultActionBean.getId().equals(actionBean.getId())){
            isMissing = false;
          }
        }
        //If the actionBean wasn't pick up.
        if(isMissing){
          //We need to save it as failed.
          actionBean.setCompleted(true);
          actionBean.setFailed(true);
          actionBean.setResponse(new JSONObject().put(ServerAction.ERROR_STATE, "Server did NOT respond on time"));
          APILocator.getServerActionAPI().saveServerActionBean(actionBean);
         
          //Add it to the results.
          resultActionBeans.add(actionBean);
        }
      }
    }
   
    //Iterate over all the results gathered.
    for (ServerActionBean resultActionBean : resultActionBeans) {
      JSONObject jsonNodeStatusObject = null;
     
      //If the result is failed we need to gather the info available.
      if(resultActionBean.isFailed()){
        Logger.error(ClusterResource.class,
            "Error trying to get Node Status for server " + resultActionBean.getServerId());
       
        jsonNodeStatusObject =
            ClusterUtilProxy.createFailedJson(APILocator.getServerAPI().getServer(resultActionBean.getServerId()));
     
        //If the result is OK we need to get the response object.
      } else {
        jsonNodeStatusObject = resultActionBean.getResponse().getJSONObject(NodeStatusServerAction.JSON_NODE_STATUS);
        jsonNodeStatusObject.put("myself", myServerId.equals(resultActionBean.getServerId()));
       
        //Check Test File Asset
        if(jsonNodeStatusObject.has("assetsStatus")
            && jsonNodeStatusObject.getString("assetsStatus").equals("green")
            && jsonNodeStatusObject.has("assetsTestPath")){
View Full Code Here

      ResourceResponse responseResource = new ResourceResponse( initData.getParamsMap() );
     
      NodeStatusServerAction nodeStatusServerAction = new NodeStatusServerAction();
      Long timeoutSeconds = new Long(1);
     
      ServerActionBean nodeStatusServerActionBean =
          nodeStatusServerAction.getNewServerAction(localServerId, remoteServerID, timeoutSeconds);
     
      nodeStatusServerActionBean =
          APILocator.getServerActionAPI().saveServerActionBean(nodeStatusServerActionBean);
     
      //Waits for 3 seconds in order server respond.
      int maxWaitTime =
          timeoutSeconds.intValue() * 1000 + Config.getIntProperty("CLUSTER_SERVER_THREAD_SLEEP", 2000) ;
      int passedWaitTime = 0;
     
      //Trying to NOT wait whole time for returning the info.
      while (passedWaitTime <= maxWaitTime){
        try {
            Thread.sleep(10);
            passedWaitTime += 10;
           
            nodeStatusServerActionBean =
                APILocator.getServerActionAPI().findServerActionBean(nodeStatusServerActionBean.getId());
           
            //No need to wait if we have all Action results.
            if(nodeStatusServerActionBean != null && nodeStatusServerActionBean.isCompleted()){
              passedWaitTime = maxWaitTime + 1;
            }
           
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
            passedWaitTime = maxWaitTime + 1;
        }
      }
     
      //If the we don't have the info after the timeout
      if(!nodeStatusServerActionBean.isCompleted()){
        nodeStatusServerActionBean.setCompleted(true);
        nodeStatusServerActionBean.setFailed(true);
        nodeStatusServerActionBean.setResponse(new JSONObject().put(ServerAction.ERROR_STATE, "Server did NOT respond on time"));
        APILocator.getServerActionAPI().saveServerActionBean(nodeStatusServerActionBean);
      }
     
      JSONObject jsonNodeStatusObject = null;
     
      //If the we have a failed job.
      if(nodeStatusServerActionBean.isFailed()){
        jsonNodeStatusObject =
            ClusterUtilProxy.createFailedJson(APILocator.getServerAPI().getServer(nodeStatusServerActionBean.getServerId()));
         
      //If everything is OK.
      } else {
        jsonNodeStatusObject =
                nodeStatusServerActionBean.getResponse().getJSONObject(NodeStatusServerAction.JSON_NODE_STATUS);
       
        //Check Test File Asset
        if(jsonNodeStatusObject.has("assetsStatus")
            && jsonNodeStatusObject.getString("assetsStatus").equals("green")
            && jsonNodeStatusObject.has("assetsTestPath")){
View Full Code Here

TOP

Related Classes of com.dotcms.enterprise.cluster.action.model.ServerActionBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.