private List<String> terminateNodes(Status endStatus) {
   List<String> endNodes = new ArrayList<String>();
   for (Map.Entry<String, NodeInstance> entry : executionPaths.entrySet()) {
     if (entry.getValue().started) {
       NodeDef nodeDef = def.getNode(entry.getValue().nodeName);
       if (!(nodeDef instanceof ControlNodeDef)) {
         NodeHandler nodeHandler = newInstance(nodeDef.getHandlerClass());
         try {
           if (endStatus == Status.KILLED) {
             nodeHandler.kill(new Context(nodeDef, entry.getKey(), null));
           } else {
             if (endStatus == Status.FAILED) {
               nodeHandler.fail(new Context(nodeDef, entry.getKey(), null));
             }
           }
           endNodes.add(nodeDef.getName());
         } catch (Exception ex) {
           log.warn(
               XLog.STD,
               "Error Changing node state to [{0}] for Node [{1}]",
               endStatus.toString(),
               nodeDef.getName(),
               ex);
         }
       }
     }
   }
   return endNodes;
 }
Beispiel #2
0
  public void updateStatus(Status status) {
    StringBuilder query = new StringBuilder();
    query.append("UPDATE Annotation SET status='").append(status.toString()).append("' ");
    query.append("WHERE pid='").append(getPid()).append("' ");

    DbManager.executeUpdate(query.toString());
  }
  @Override
  public void write(DataOutput dOut) throws IOException {
    dOut.writeUTF(instanceId);

    // Hadoop Configuration has to get its act right
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    conf.writeXml(baos);
    baos.close();
    byte[] array = baos.toByteArray();
    dOut.writeInt(array.length);
    dOut.write(array);

    def.write(dOut);
    dOut.writeUTF(status.toString());
    dOut.writeInt(executionPaths.size());
    for (Map.Entry<String, NodeInstance> entry : executionPaths.entrySet()) {
      dOut.writeUTF(entry.getKey());
      dOut.writeUTF(entry.getValue().nodeName);
      dOut.writeBoolean(entry.getValue().started);
    }
    dOut.writeInt(persistentVars.size());
    for (Map.Entry<String, String> entry : persistentVars.entrySet()) {
      dOut.writeUTF(entry.getKey());
      writeStringAsBytes(entry.getValue(), dOut);
    }
  }
  private void updateNotification(String listenerName, Message message, Status status) {
    String sql =
        "UPDATE \""
            + tablePrefix
            + listenerName
            + "\" SET "
            + (status == Status.FAILED
                ? "failCount=failCount+1,"
                : "") // increase failCount if it's FAILED
            + " status=? WHERE id=?";

    Connection con = null;
    try {
      con = dataSource.getConnection();
      PreparedStatement pstmt = con.prepareStatement(sql);
      pstmt.setString(1, status.toString());
      pstmt.setInt(2, message.getId());
      int count = pstmt.executeUpdate();
      if (count == 0) LOGGER.warn("No rows affected by update of:" + message + ", " + status);
    } catch (SQLException e) {
      LOGGER.error("Failed updating message log", e);
    } finally {
      if (con != null) {
        try {
          con.close();
        } catch (Exception e) {
          LOGGER.error(e);
        }
      }
    }
  }
  public static void packageIntent(
      Intent intent, String title, Priority priority, Status status, String date) {

    intent.putExtra(ToDoItem.TITLE, title);
    intent.putExtra(ToDoItem.PRIORITY, priority.toString());
    intent.putExtra(ToDoItem.STATUS, status.toString());
    intent.putExtra(ToDoItem.DATE, date);
  }
Beispiel #6
0
 public static Status getStatusValue(final String text) {
   final Status[] values = values();
   for (final Status value : values) {
     if (value.toString().equals(text)) {
       return value;
     }
   }
   throw new IllegalArgumentException(text + " is not a valid status.");
 }
  public static Bundle packageBundle(String title, Priority priority, Status status, String date) {
    Bundle data = new Bundle();
    data.putString(ToDoItem.TITLE, title);
    data.putString(ToDoItem.PRIORITY, priority.toString());
    data.putString(ToDoItem.STATUS, status.toString());
    data.putString(ToDoItem.DATE, date);

    return data;
  }
Beispiel #8
0
 // 根据操作状态输出AJAX
 protected String ajax(Status status) {
   HttpServletResponse response = initResponse(HEADER_JSON_CONTENT_TYPE);
   try {
     Map<String, String> jsonMap = new HashMap<String, String>();
     jsonMap.put(STATUS_PARAMETER_NAME, status.toString());
     JsonUtil.getMapper().writeValue(response.getWriter(), jsonMap);
   } catch (IOException e) {
     throw new IllegalArgumentException(e);
   }
   return NONE;
 }
Beispiel #9
0
  /**
   * Use this in place of valueOf.
   *
   * @param value real value
   * @return Status corresponding to the value
   */
  public static Status fromValue(String value) {
    if (value == null || "".equals(value)) {
      throw new IllegalArgumentException("Value cannot be null or empty!");
    }

    for (Status enumEntry : Status.values()) {
      if (enumEntry.toString().equals(value)) {
        return enumEntry;
      }
    }

    throw new IllegalArgumentException("Cannot create enum from " + value + " value!");
  }
    private void write(
        final Address address,
        final MapquestResult.MapquestStatus status,
        final MapquestResult.Result result,
        final Status rejectCause) {
      // Why do I always have to go so dirty when writing files?
      final String[] fields = new String[18];

      for (int i = 0; i < fields.length; i++) fields[i] = "";

      if (address != null) {
        fields[0] = address.getId() != null ? address.getId() : "";
        fields[1] = address.getStreet() != null ? address.getStreet() : "";
        fields[2] = address.getNumber() != null ? address.getNumber() : "";
        fields[3] = address.getZipcode() != null ? address.getZipcode() : "";
        fields[4] = address.getMunicipality() != null ? address.getMunicipality() : "";
        fields[5] = address.getCountry() != null ? address.getCountry() : "";
      }

      if (rejectCause != null) {
        fields[6] = rejectCause.toString();
      }

      if (result != null) {
        fields[7] = result.getLongitude().toString();
        fields[8] = result.getLatitude().toString();

        final Coord wgsCoord = new Coord(result.getLongitude(), result.getLatitude());
        final Coord chCoord = new WGS84toCH1903LV03().transform(wgsCoord);
        fields[9] = "" + chCoord.getX();
        fields[10] = "" + chCoord.getY();
        fields[11] = result.getGeocodeQuality().toString();
        fields[12] = result.getGeocodeQualityCode();
        fields[13] = result.getStreet();
        fields[14] = result.getZip();
        fields[15] = result.getCity();
        fields[16] = result.getCountry();
        fields[17] = status.toString();
      }

      final String line = CsvUtils.buildCsvLine(SEP, QUOTE, fields);

      try {
        this.writer.newLine();
        this.writer.write(line);
      } catch (IOException e) {
        throw new UncheckedIOException(e);
      }
    }
Beispiel #11
0
  public Map<String, Object> toObject() {
    HashMap<String, Object> flowObj = new HashMap<String, Object>();
    flowObj.put("type", "executableflow");
    flowObj.put("executionId", executionId);
    flowObj.put("executionPath", executionPath);
    flowObj.put("flowId", flowId);
    flowObj.put("projectId", projectId);
    flowObj.put("submitTime", submitTime);
    flowObj.put("startTime", startTime);
    flowObj.put("endTime", endTime);
    flowObj.put("status", flowStatus.toString());
    flowObj.put("submitUser", submitUser);
    flowObj.put("flowParameters", this.flowParameters);
    flowObj.put("notifyOnFirstFailure", this.notifyOnFirstFailure);
    flowObj.put("notifyOnLastFailure", this.notifyOnLastFailure);
    flowObj.put("successEmails", successEmails);
    flowObj.put("failureEmails", failureEmails);
    flowObj.put("failureAction", failureAction.toString());
    flowObj.put("pipelineLevel", pipelineLevel);
    flowObj.put("version", version);

    ArrayList<Object> props = new ArrayList<Object>();
    for (FlowProps fprop : flowProps.values()) {
      HashMap<String, Object> propObj = new HashMap<String, Object>();
      String source = fprop.getSource();
      String inheritedSource = fprop.getInheritedSource();

      propObj.put("source", source);
      if (inheritedSource != null) {
        propObj.put("inherited", inheritedSource);
      }
      props.add(propObj);
    }
    flowObj.put("properties", props);

    ArrayList<Object> nodes = new ArrayList<Object>();
    for (ExecutableNode node : executableNodes.values()) {
      nodes.add(node.toObject());
    }
    flowObj.put("nodes", nodes);

    ArrayList<String> proxyUserList = new ArrayList<String>(proxyUsers);

    flowObj.put("proxyUsers", proxyUserList);

    return flowObj;
  }
  public List<T> loadNotifications(String listenerName, Status status, int max, int maxFailCount) {
    String sql =
        "SELECT notification, failCount FROM \""
            + tablePrefix
            + listenerName
            + "\" WHERE status=? "
            + (maxFailCount <= 0 ? "" : " and failCount <= ?"); // conditional criterion

    Connection con = null;
    List<T> notifications = new ArrayList<T>();
    try {
      con = dataSource.getConnection();
      PreparedStatement pstmt = con.prepareStatement(sql);
      pstmt.setString(1, status.toString());
      if (maxFailCount > 0) pstmt.setInt(2, maxFailCount);
      pstmt.setFetchSize(max);
      ResultSet resultSet = pstmt.executeQuery();
      int count = 0;
      while (resultSet.next() && ++count <= max) {
        try {
          T notification = deserialise(resultSet.getBytes(1));
          notification.setFailCount(resultSet.getInt(2));
          notifications.add(notification);
          count++;
        } catch (Exception e) {
          LOGGER.warn("Failed deserialising notification", e);
        }
      }
    } catch (SQLException e) {
      LOGGER.error("Failed updating notification log", e);
    } finally {
      if (con != null) {
        try {
          con.close();
        } catch (Exception e) {
          LOGGER.error(e);
        }
      }
    }
    return notifications;
  }
Beispiel #13
0
  public void writeExternal(ObjectOutput out) throws IOException {
    if (status != null) {
      out.writeBoolean(true);
      out.writeUTF(status.toString());
    } else {
      out.writeBoolean(false);
    }

    if (previousStatus != null) {
      out.writeBoolean(true);
      out.writeUTF(previousStatus.toString());
    } else {
      out.writeBoolean(false);
    }

    if (actualOwner != null) {
      out.writeBoolean(true);
      actualOwner.writeExternal(out);
    } else {
      out.writeBoolean(false);
    }

    if (createdBy != null) {
      out.writeBoolean(true);
      createdBy.writeExternal(out);
    } else {
      out.writeBoolean(false);
    }

    if (createdOn != null) {
      out.writeBoolean(true);
      out.writeLong(createdOn.getTime());
    } else {
      out.writeBoolean(false);
    }

    if (activationTime != null) {
      out.writeBoolean(true);
      out.writeLong(activationTime.getTime());
    } else {
      out.writeBoolean(false);
    }

    if (expirationTime != null) {
      out.writeBoolean(true);
      out.writeLong(expirationTime.getTime());
    } else {
      out.writeBoolean(false);
    }

    out.writeBoolean(skipable);

    if (workItemId != -1) {
      out.writeBoolean(true);
      out.writeLong(workItemId);
    } else {
      out.writeBoolean(false);
    }

    if (processInstanceId != -1) {
      out.writeBoolean(true);
      out.writeLong(processInstanceId);
    } else {
      out.writeBoolean(false);
    }

    if (documentAccessType != null) {
      out.writeBoolean(true);
      out.writeObject(documentAccessType);
    } else {
      out.writeBoolean(false);
    }

    if (documentType != null) {
      out.writeBoolean(true);
      out.writeUTF(documentType);
    } else {
      out.writeBoolean(false);
    }

    if (documentContentId != -1) {
      out.writeBoolean(true);
      out.writeLong(documentContentId);
    } else {
      out.writeBoolean(false);
    }

    if (outputAccessType != null) {
      out.writeBoolean(true);
      out.writeObject(outputAccessType);
    } else {
      out.writeBoolean(false);
    }

    if (outputType != null) {
      out.writeBoolean(true);
      out.writeUTF(outputType);
    } else {
      out.writeBoolean(false);
    }

    if (outputContentId != -1) {
      out.writeBoolean(true);
      out.writeLong(outputContentId);
    } else {
      out.writeBoolean(false);
    }

    if (faultName != null) {
      out.writeBoolean(true);
      out.writeUTF(faultName);
    } else {
      out.writeBoolean(false);
    }

    if (faultAccessType != null) {
      out.writeBoolean(true);
      out.writeObject(faultAccessType);
    } else {
      out.writeBoolean(false);
    }

    if (faultType != null) {
      out.writeBoolean(true);
      out.writeUTF(faultType);
    } else {
      out.writeBoolean(false);
    }

    if (faultContentId != -1) {
      out.writeBoolean(true);
      out.writeLong(faultContentId);
    } else {
      out.writeBoolean(false);
    }

    if (parentId != -1) {
      out.writeBoolean(true);
      out.writeLong(parentId);
    } else {
      out.writeBoolean(false);
    }

    CollectionUtils.writeCommentList(comments, out);
    CollectionUtils.writeAttachmentList(attachments, out);
  }
Beispiel #14
0
 @Override
 public String getStatus() {
   return status.toString();
 }
Beispiel #15
0
  /**
   * returns a list of feed objects based on a number of optional query parameters. If set to {@link
   * null}, a parameter is ignored.
   *
   * @param query Full text {@link String} search parameter. Should return any feeds matching this
   *     string
   * @param content parameter of type {@link Content} describing the type of results
   * @param tag Returns feeds containing datastreams tagged with the search query
   * @param user Returns feeds created by the user specified.
   * @param units Returns feeds containing datastreams with units specified by the search query.
   * @param status Parameter of type {@link Status}
   * @param order Parameter of type {@link Order}. Used for ordering the results.
   * @param show_user Include user login and user level for each feed. {@link Boolean} with possible
   *     values: true, false (default)
   * @param lat Used to find feeds located around this latitude. Used if ids/_datastreams_ are not
   *     specified.
   * @param lon Used to find feeds located around this longitude. Used if ids/_datastreams_ are not
   *     specified.
   * @param distance search radius
   * @param distance_units miles or kms
   * @return Array of {@link Feed} objects
   * @throws CosmException
   */
  public Feed[] getFeeds(
      String query,
      Content content,
      String tag,
      String user,
      String units,
      Status status,
      Order order,
      Boolean show_user,
      Double lat,
      Double lon,
      Double distance,
      DistanceUnit distance_units)
      throws CosmException {
    String q = "";
    boolean bAdd = false;

    if (query != null) {
      if (bAdd) q += '&';
      q += "q=" + query;
      bAdd = true;
    }
    if (content != null) {
      if (bAdd) q += '&';
      q += "content=" + content.toString();
      bAdd = true;
    }
    if (tag != null) {
      if (bAdd) q += '&';
      q += "tag=" + tag;
      bAdd = true;
    }
    if (user != null) {
      if (bAdd) q += '&';
      q += "user="******"units=" + units;
      bAdd = true;
    }
    if (status != null) {
      if (bAdd) q += '&';
      q += "status=" + status.toString();
      bAdd = true;
    }
    if (order != null) {
      if (bAdd) q += '&';
      q += "order=" + order.toString();
      bAdd = true;
    }
    if (show_user != null) {
      if (bAdd) q += '&';
      q += "show_user="******"lat=" + lat;
      bAdd = true;
    }
    if (lon != null) {
      if (bAdd) q += '&';
      q += "lon=" + lon;
      bAdd = true;
    }
    if (distance != null) {
      if (bAdd) q += '&';
      q += "distance=" + distance;
      bAdd = true;
    }
    if (distance_units != null) {
      if (bAdd) q += '&';
      q += "distance_units=" + distance_units.toString();
      bAdd = true;
    }

    try {
      URI uri =
          new URI(
              API_SCHEME,
              API_HOST,
              API_VERSION + API_RESOURCE_FEEDS + JSON_FILE_EXTENSION,
              q,
              null);
      HttpGet hr = new HttpGet(uri);
      HttpResponse response = this.client.execute(hr);
      StatusLine statusLine = response.getStatusLine();
      String body = this.client.getBody(response);
      if (statusLine.getStatusCode() == 200) {
        return CosmFactory.toFeeds(body);
      }
      throw new CosmException(statusLine, body);
    } catch (IOException e) {
      throw new CosmException(IO_EXCEPTION_MESSAGE);
    } catch (URISyntaxException e) {
      throw new CosmException(URL_SYNTAX_EXCEPTION_MESSAGE);
    }
  }
Beispiel #16
0
 public String toString() {
   return status.toString();
 }
 // This function will set the current status of the vehicle based on a string input
 public void setStatus(String s) {
   if (status == null || !status.toString().equals(s)) {
     status = loadStatus(s); // Set the status of the vehicle
     MarkDirty(); // Mark the vehicle as dirty
   }
 } // End of the setStatus(String s) function
 // This function returns the current status of the vehicle
 public String getStatus() {
   return status.toString();
 } // End of getStatus
Beispiel #19
0
 public String getStatusAsString() {
   return status.toString().replaceAll("_", " ");
 }