Example #1
0
  /**
   * Function that takes a user given date string and attempts to convert it to a Java Date object.
   * One of 2 formats are supported:
   *
   * <p>1) Date/Time format as defined by SimpleDateFormat (i.e. 5/18/2008 4:00 PM) 2) Hour/Minutes
   * notation. In this case, the current date is used.
   *
   * @param str The date string to parse.
   * @return The equivenlent Date object, or null if the date could not be parsed.
   */
  private Date parseDateString(String str) {
    final DateFormat df = SimpleDateFormat.getInstance();
    try {
      return df.parse(str);
    } catch (ParseException e) {
      // Ignored
    }

    // Fall back to HH:MM notation if date parse fails.
    String time[] = str.split(":");
    if (time.length != 2) {
      return null;
    }

    try {
      int hours = Integer.parseInt(time[0]);
      int minutes = Integer.parseInt(time[1]);
      Calendar c = Calendar.getInstance();
      c.set(Calendar.HOUR_OF_DAY, hours);
      c.set(Calendar.MINUTE, minutes);
      return c.getTime();
    } catch (NumberFormatException e) {
      return null;
    }
  }
 @Override
 public String toSQLString() {
   if (value != null) {
     if (Number.class.isAssignableFrom(value.getClass()))
       return NumberFormat.getInstance().format((Number) value);
     if (Date.class.isAssignableFrom(value.getClass()))
       return SimpleDateFormat.getInstance().format((Date) value);
     return "'" + value + "'";
   }
   return Misc.nvl(value, "");
 }
Example #3
0
  /**
   * Call this method for starting an asynchronous deployment given a proper deploy request - proxy
   * method for {@link QNodeHandler}. Returns a {@link QueryStatus} with the status of the request.
   */
  public DeployInfo deploy(List<DeployRequest> deployRequests) {

    // A new unique version number is generated.
    long version = context.getCoordinationStructures().uniqueVersionId();

    // Generate the list of actions per DNode
    Map<String, List<DeployAction>> actionsPerDNode =
        generateDeployActionsPerDNode(deployRequests, version);

    // Starting the countdown latch.
    ICountDownLatch countDownLatchForDeploy =
        context.getCoordinationStructures().getCountDownLatchForDeploy(version);
    Set<String> dnodesInvolved = actionsPerDNode.keySet();
    countDownLatchForDeploy.setCount(dnodesInvolved.size());

    // Sending deploy signals to each DNode
    for (Map.Entry<String, List<DeployAction>> actionPerDNode : actionsPerDNode.entrySet()) {
      DNodeService.Client client = null;
      try {
        client = context.getDNodeClient(actionPerDNode.getKey(), false);
        client.deploy(actionPerDNode.getValue(), version);
      } catch (Exception e) {
        log.error("Error sending deploy actions to DNode [" + actionPerDNode.getKey() + "]", e);
        abortDeploy(new ArrayList<String>(actionsPerDNode.keySet()), version);
        DeployInfo errDeployInfo = new DeployInfo();
        errDeployInfo.setError("Error connecting to DNode " + actionPerDNode.getKey());
        return errDeployInfo;
      } finally {
        client.getOutputProtocol().getTransport().close();
      }
    }

    // Initiating an asynchronous process to manage the deployment
    deployThread.execute(
        new ManageDeploy(
            new ArrayList(actionsPerDNode.keySet()),
            deployRequests,
            version,
            context.getConfig().getLong(QNodeProperties.DEPLOY_TIMEOUT, -1),
            context.getConfig().getLong(QNodeProperties.DEPLOY_SECONDS_TO_CHECK_ERROR)));

    DeployInfo deployInfo = new DeployInfo();
    deployInfo.setVersion(version);
    deployInfo.setStartedAt(SimpleDateFormat.getInstance().format(new Date()));
    return deployInfo;
  }
  @Test
  public void testToSecureImage() throws Exception {

    FunctionInterface fi = fff.getInstance(cl, "ToSecureImage");
    fi.reset();
    fi.insertOperand("SECURE");
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Binary.class, o.getClass());

    fi.reset();
    fi.insertOperand(null);
    o = fi.evaluateWithTypeChecking();
    assertNull(o);

    System.err.println(System.currentTimeMillis());
    long l = (new Long("1234567890000").longValue() - System.currentTimeMillis());
    Calendar c = Calendar.getInstance();
    c.add(Calendar.MILLISECOND, (int) l);
    System.err.println(SimpleDateFormat.getInstance().format(c.getTime()));
  }
Example #5
0
  private static void restoreStateFromMemento(IMemento memento) {
    IMemento[] urlMementos = memento.getChildren(URL_WAYPOINT);

    for (IMemento urlMemento : urlMementos) {
      String urlString = urlMemento.getString(URL_ATTRIBUTE);

      String author = urlMemento.getString(AUTHOR_ATTRIBUTE);
      String dateString = urlMemento.getString(DATE_ATTRIBUTE);
      String description = urlMemento.getString(DESCRIPTION_ATTRIBUTE);

      String[] tagNames = getTagNames(urlMemento);

      Date date = null;

      if (dateString != null) {
        try {
          date = SimpleDateFormat.getInstance().parse(dateString);
        } catch (ParseException e) {
          e.printStackTrace();
        }
      }

      IWaypoint waypoint =
          TagSEAPlugin.getWaypointsModel()
              .createWaypoint(URLWaypointPlugin.WAYPOINT_ID, new String[0]);

      for (String tagName : tagNames) {
        waypoint.addTag(tagName);
      }

      waypoint.setAuthor(author);
      waypoint.setDate(date);
      waypoint.setText(description);
      waypoint.setStringValue(URLWaypointUtil.URL_ATTR, urlString);
    }
  }
Example #6
0
  private void get(String[] args) throws Exception {
    String[] ONE_REQUIRED = {OPT_RESOURCEID, OPT_GROUPID, OPT_ALL};

    final DateFormat df = SimpleDateFormat.getInstance();
    OptionParser p = getOptionParser();

    p.accepts(OPT_RESOURCEID, "The id of the resource to query for maintenance")
        .withRequiredArg()
        .ofType(Integer.class);

    p.accepts(OPT_GROUPID, "The id of the group to query for maintenance")
        .withRequiredArg()
        .ofType(Integer.class);

    p.accepts(OPT_ALL, "Get all maintenance schedules");

    OptionSet options = getOptions(p, args);

    int criteria = 0;
    for (String opt : ONE_REQUIRED) {
      if (options.has(opt)) {
        criteria++;
      }
    }

    if (criteria == 0) {
      System.err.println("One of " + Arrays.toString(ONE_REQUIRED) + " is required.");
      System.exit(-1);
    } else if (criteria > 1) {
      System.err.println("Only one of " + Arrays.toString(ONE_REQUIRED) + " may be specified");
      System.exit(-1);
    }

    HQApi api = getApi(options);
    MaintenanceApi maintenanceApi = api.getMaintenanceApi();

    if (options.has(OPT_ALL)) {
      MaintenancesResponse schedules = maintenanceApi.getAll(null);
      checkSuccess(schedules);
      XmlUtil.serialize(schedules, System.out, Boolean.TRUE);
    } else {
      MaintenanceResponse response = null;
      Integer id = null;

      if (options.has(OPT_GROUPID)) {
        id = (Integer) getRequired(options, OPT_GROUPID);
        response = maintenanceApi.get(id);
      } else if (options.has(OPT_RESOURCEID)) {
        id = (Integer) getRequired(options, OPT_RESOURCEID);
        ResourceResponse resourceResponse = api.getResourceApi().getResource(id, false, false);
        checkSuccess(resourceResponse);
        response = maintenanceApi.get(resourceResponse.getResource());
      }
      checkSuccess(response);
      MaintenanceEvent event = response.getMaintenanceEvent();

      if (event != null
          && event.getState() != null
          && event.getStartTime() != 0
          && event.getEndTime() != 0) {

        if (event.getGroupId() > 0) {
          System.out.println("Maintenance schedule for group " + event.getGroupId());
        } else {
          System.out.println("Maintenance schedule for resource " + event.getResourceId());
        }
        System.out.println("State: " + event.getState().value());
        System.out.println("Start Time: " + df.format(event.getStartTime()));
        System.out.println("End Time: " + df.format(event.getEndTime()));
      } else {
        if (options.has(OPT_GROUPID)) {
          System.out.println("No maintenance events found for group " + id);
        } else if (options.has(OPT_RESOURCEID)) {
          System.out.println("No maintenance events found for resource " + id);
        }
      }
    }
  }