Esempio n. 1
0
  /** Method to handle deploying and removing state clusters. */
  public void handleDeployingRemovingClusters() {

    // Creating property map for deploying state.
    Map<String, Object> deployingStateMap = new HashMap<String, Object>();
    deployingStateMap.put(
        com.impetus.ankush2.constant.Constant.Keys.STATE,
        com.impetus.ankush2.constant.Constant.Cluster.State.DEPLOYING.toString());
    // Creating property map for removing state.
    Map<String, Object> removingStateMap = new HashMap<String, Object>();
    removingStateMap.put(
        com.impetus.ankush2.constant.Constant.Keys.STATE,
        com.impetus.ankush2.constant.Constant.Cluster.State.REMOVING.toString());

    // Map<String, Object> registeringStateMap = new HashMap<String,
    // Object>();
    // registeringStateMap.put(com.impetus.ankush2.constant.Constant.Keys.STATE,
    // com.impetus.ankush2.constant.Constant.Cluster.State.REGISTERING);

    // making list of maps
    List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
    maps.add(deployingStateMap);
    maps.add(removingStateMap);
    // maps.add(registeringStateMap);

    // list of deploying + removing state clusters.
    List<Cluster> clusters = clusterManager.getAllByDisjunctionveNormalQuery(maps);

    // iterating over the all deploying/removing state clusters.
    for (Cluster cluster : clusters) {
      // getting clusterable object.
      try {
        // setting state as crashed.
        cluster.setState(Constant.Cluster.State.SERVER_CRASHED.toString());
        // getting cluster conf.
        ClusterConfig conf = cluster.getClusterConfig();
        // setting id of cluster inside conf.
        conf.setClusterId(cluster.getId());
        // setting state as error.
        conf.setState(com.impetus.ankush2.constant.Constant.Cluster.State.ERROR);
        // adding error message.
        conf.addError("Deploy", "Server crashed unexpectedly.");
        // saving cluster conf.
        cluster.setClusterConf(conf);
        // saving cluster.
        clusterManager.save(cluster);
      } catch (Exception e) {
        log.error(e.getMessage());
        try {
          // setting server crashed as state.
          cluster.setState(Constant.Cluster.State.SERVER_CRASHED.toString());
          // saving in db.
          clusterManager.save(cluster);
        } catch (Exception subExe) {
          log.error(subExe.getMessage());
        }
      }
    }
  }
Esempio n. 2
0
  /** Function that changed the state of all inprogress operations to ServerCrashed */
  public void handleInProgressOperations() {
    try {
      // Creating property map for deploying state.
      Map<String, Object> inProgressStatusMap = new HashMap<String, Object>();
      inProgressStatusMap.put(
          com.impetus.ankush2.constant.Constant.Keys.STATUS,
          com.impetus.ankush2.constant.Constant.Operation.Status.INPROGRESS.toString());

      // making list of maps
      List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
      maps.add(inProgressStatusMap);

      List<Operation> operations = operationManager.getAllByPropertyValue(inProgressStatusMap);

      for (Operation operation : operations) {
        try {
          operation.setStatus(
              com.impetus.ankush2.constant.Constant.Operation.Status.ERROR.toString());
          operation.setCompletedAt(new Date());
          operation.getData().put("Error", "Server crashed unexpectedly.");
          operationManager.save(operation);
        } catch (Exception e) {
          log.error(e.getMessage());
          try {
            operation.setStatus(
                com.impetus.ankush2.constant.Constant.Operation.Status.ERROR.toString());
            operationManager.save(operation);
          } catch (Exception subExe) {
            log.error(subExe.getMessage());
          }
        }
      }
    } catch (Exception e) {
      log.error(e.getMessage());
    }
  }
Esempio n. 3
0
  /** Method to handle deploying, removing and adding state nodes. */
  public void handleDeployingRemovingNodes() {

    // Creating property map for deploying state.
    Map<String, Object> deployingStateMap = new HashMap<String, Object>();
    deployingStateMap.put(
        com.impetus.ankush2.constant.Constant.Keys.STATE,
        com.impetus.ankush2.constant.Constant.Node.State.DEPLOYING.toString());
    // Creating property map for removing state.
    Map<String, Object> removingStateMap = new HashMap<String, Object>();
    removingStateMap.put(
        com.impetus.ankush2.constant.Constant.Keys.STATE,
        com.impetus.ankush2.constant.Constant.Node.State.REMOVING.toString());

    Map<String, Object> addingStateMap = new HashMap<String, Object>();
    addingStateMap.put(
        com.impetus.ankush2.constant.Constant.Keys.STATE,
        com.impetus.ankush2.constant.Constant.Node.State.ADDING.toString());

    // making list of maps
    List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
    maps.add(deployingStateMap);
    maps.add(removingStateMap);
    maps.add(addingStateMap);

    try {
      // list of deploying + removing state nodes.
      List<Node> nodes = nodeManager.getAllByDisjunctionveNormalQuery(maps);
      // setting node state as Server_Crashed
      for (Node node : nodes) {
        node.setState(Constant.Node.State.SERVER_CRASHED.toString());
        nodeManager.save(node);
      }
    } catch (Exception e) {
      log.error(e.getMessage());
    }
  }
Esempio n. 4
0
  /**
   * Gets the object.
   *
   * @param className the class name
   * @return the object
   */
  public static Object getObject(String className) {
    Object obj = null;
    try {
      Class<?> clazz = Class.forName(className);
      Constructor<?> co = clazz.getConstructor();
      obj = co.newInstance(null);
    } catch (SecurityException e) {
      LOG.error(e.getMessage(), e);
    } catch (IllegalArgumentException e) {
      LOG.error(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
      LOG.error(e.getMessage(), e);
    } catch (NoSuchMethodException e) {
      LOG.error(e.getMessage(), e);
    } catch (InstantiationException e) {
      LOG.error(e.getMessage(), e);
    } catch (IllegalAccessException e) {
      LOG.error(e.getMessage(), e);
    } catch (InvocationTargetException e) {
      LOG.error(e.getMessage(), e);
    }

    return obj;
  }