Ejemplo n.º 1
0
 /**
  * Amazon SimpleDB client.
  *
  * @return the Amazon SimpleDB client
  */
 public AmazonSimpleDB sdbClient() {
   AmazonSimpleDB client = new AmazonSimpleDBClient(cred);
   // us-east-1 has special naming
   // http://docs.amazonwebservices.com/general/latest/gr/rande.html#sdb_region
   if (region == null || region.equals("us-east-1")) {
     client.setEndpoint("sdb.amazonaws.com");
   } else {
     client.setEndpoint("sdb." + region + ".amazonaws.com");
   }
   return client;
 }
  private void invalidateCustoms(String dateTime) {
    String invalidsNextToken = null;
    do {
      SelectRequest invalidsRequest =
          new SelectRequest(
              "select `itemName()` from `"
                  + AdWhirlUtil.DOMAIN_CUSTOMS_INVALID
                  + "` where dateTime < '"
                  + dateTime
                  + "'");
      invalidsRequest.setNextToken(invalidsNextToken);
      try {
        SelectResult invalidsResult = sdb.select(invalidsRequest);
        invalidsNextToken = invalidsResult.getNextToken();
        List<Item> invalidsList = invalidsResult.getItems();

        for (Item item : invalidsList) {
          String aid = item.getName();
          deleteInvalid(AdWhirlUtil.DOMAIN_CUSTOMS_INVALID, aid);
        }
      } catch (Exception e) {
        AdWhirlUtil.logException(e, log);

        // Eventually we'll get a 'stale request' error and need to start over.
        invalidsNextToken = null;
      }
    } while (invalidsNextToken != null);
  }
Ejemplo n.º 3
0
  private boolean checkRound() {
    System.out.println("Start " + current);

    // Add to SimpleDB
    addMembership();

    // Build list of servers
    SelectRequest selectRequest = new SelectRequest("select * from " + simpleDBDomain);
    List<Server> ss = new ArrayList<Server>();
    for (Item item : sdb.select(selectRequest).getItems()) {
      ss.add(new Server(item.getName()));
    }

    if (ss.size() > 0) {
      // Probe random server and remove if inactive
      int i = r.nextInt(ss.size());
      Server s = ss.get(i);
      System.out.println("Checking " + s);
      // if(!current.equals(s)) {
      if (!probe(s)) {
        ss.remove(i);
      }
      // }
      // Replace servers with new list
      Collections.shuffle(ss, r);
      writelock.lock();
      servers = ss;
      writelock.unlock();
    }

    System.out.println("End");
    return true;
  }
Ejemplo n.º 4
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#deleteCollaboration(ca.unb.cs.pcsf.db.Collaboration)
   */
  public void deleteCollaboration(Collaboration collaboration) {
    logger.debug(LOGPRE + "deleteCollaboration() start" + LOGPRE);

    if (isCollaborationExist(collaboration.getName())) {
      logger.info("Deleting participants...");
      List<Participant> participants = collaboration.getParticipants();
      for (Participant p : participants) {
        sdb.deleteAttributes(new DeleteAttributesRequest(DOMAIN_PARTICIPANT, p.getId()));
      }
      sdb.deleteAttributes(
          new DeleteAttributesRequest(DOMAIN_COLLABORATION, collaboration.getId()));

      logger.info("Delete Done!");
      logger.debug(LOGPRE + "deleteCollaboration() end" + LOGPRE);
    }
  }
Ejemplo n.º 5
0
 private boolean addMembership() {
   List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();
   replaceableAttributes.add(new ReplaceableAttribute("ip", current.ip.getHostAddress(), true));
   replaceableAttributes.add(new ReplaceableAttribute("port", current.port.toString(), true));
   sdb.putAttributes(
       new PutAttributesRequest(simpleDBDomain, current.toString(), replaceableAttributes));
   return true;
 }
 private void deleteInvalid(String domain, String id) {
   log.debug("Deleting invalid <" + domain + ", " + id + ">");
   DeleteAttributesRequest deleteRequest = new DeleteAttributesRequest(domain, id);
   try {
     sdb.deleteAttributes(deleteRequest);
   } catch (Exception e) {
     AdWhirlUtil.logException(e, log);
     return;
   }
 }
Ejemplo n.º 7
0
  /**
   * select data from a domain
   *
   * @param selectExpression
   * @return the data selected from the domain
   */
  private List<Item> getDataFromDomain(String selectExpression) {
    logger.debug(LOGPRE + "getDataFromDomain() start" + LOGPRE);
    logger.debug("Selecting: " + selectExpression);

    logger.debug("Getting data...");
    SelectRequest selectRequest = new SelectRequest(selectExpression);

    logger.debug(LOGPRE + "getDataFromDomain() end" + LOGPRE);
    return sdb.select(selectRequest).getItems();
  }
Ejemplo n.º 8
0
  /**
   * create a domain
   *
   * @param domainName
   * @return if the domain been created successfully
   */
  private void createDomain(String domainName) {
    logger.debug(LOGPRE + "createDomain() start" + LOGPRE);

    if (!isDomainExist(domainName)) {
      logger.info("Creating domain called <" + domainName + ">...");
      sdb.createDomain(new CreateDomainRequest(domainName));
      logger.info("Domain <" + domainName + "> has been created");
    }

    logger.debug(LOGPRE + "createDomain() end" + LOGPRE);
  }
Ejemplo n.º 9
0
 /**
  * Issue a probe request to remoteip:remoteport. If the server does not respond, remove it from
  * SimpleDB.
  *
  * @return
  */
 private boolean probe(Server s) {
   if (RPCClient.probe(s)) {
     System.out.println(s + " Active");
     return true;
   } else {
     System.out.println(s + " Inactive");
     sdb.deleteAttributes(new DeleteAttributesRequest(simpleDBDomain, s.toString()));
     System.out.println(s + " Removed");
     return false;
   }
 }
Ejemplo n.º 10
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#updateCollaborationState(ca.unb.cs.pcsf.db.Collaboration,
   * java.lang.String)
   */
  public void updateCollaborationState(Collaboration collaboration, String state) {
    logger.debug(LOGPRE + "updateCollaborationState() start" + LOGPRE);

    logger.info("Updating collaboration <" + collaboration.getName() + "> state to be" + state);
    String domainName = DOMAIN_COLLABORATION;
    String itemName = collaboration.getId();
    List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();

    replaceableAttributes.add(
        new ReplaceableAttribute(COLLABORATION_ATTRIBUTE_CURRENT_STATE, state, true));

    sdb.putAttributes(new PutAttributesRequest(domainName, itemName, replaceableAttributes));

    logger.debug(LOGPRE + "updateCollaborationState() end" + LOGPRE);
  }
Ejemplo n.º 11
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#update(java.lang.Object)
   */
  public void update(Object o) {
    logger.debug(LOGPRE + "update() start" + LOGPRE);

    if (o instanceof Collaboration) {
      Collaboration collaboration = (Collaboration) o;
      logger.info("Updating Collaboration <" + collaboration.getName() + ">...");

      String domainName = DOMAIN_COLLABORATION;
      String itemName = collaboration.getId();
      List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();

      replaceableAttributes.add(
          new ReplaceableAttribute(COLLABORATION_ATTRIBUTE_NAME, collaboration.getName(), true));
      for (Participant s : collaboration.getParticipants())
        replaceableAttributes.add(
            new ReplaceableAttribute(COLLABORATION_ATTRIBUTE_PARTICIPANT, s.getName(), true));

      sdb.putAttributes(new PutAttributesRequest(domainName, itemName, replaceableAttributes));
    }

    if (o instanceof Participant) {
      Participant participant = (Participant) o;
      logger.info("Updating participant <" + participant.getName() + ">...");

      String domainName = DOMAIN_PARTICIPANT;
      String itemName = participant.getId();
      List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();

      replaceableAttributes.add(
          new ReplaceableAttribute(PARTICIPANT_ATTRIBUTE_IS_REG, participant.getIsReg(), true));

      sdb.putAttributes(new PutAttributesRequest(domainName, itemName, replaceableAttributes));
    }

    logger.debug(LOGPRE + "update() end" + LOGPRE);
  }
Ejemplo n.º 12
0
  /**
   * check if the domain exist or not
   *
   * @param domainName
   * @return if certain domain exist or not
   */
  private boolean isDomainExist(String domainName) {
    logger.debug(LOGPRE + "isDomainExist() start" + LOGPRE);

    for (String dn : sdb.listDomains().getDomainNames()) {
      if (dn.equals(domainName)) {
        logger.debug("Domain <" + domainName + "> exists");
        logger.debug(LOGPRE + "isDomainExist() end" + LOGPRE);
        return true;
      }
    }

    logger.debug("Domain <" + domainName + "> doesn't exist");
    logger.debug(LOGPRE + "isDomainExist() end" + LOGPRE);
    return false;
  }
Ejemplo n.º 13
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.PcsfSimpleDBAccess#setProcessDeploymentId(java.lang.String)
   */
  @Override
  public void setProcessDeploymentId(String collaborationId, String processDeploymentId) {
    logger.debug(LOGPRE + "setProcessDeploymentId() start" + LOGPRE);

    List<ReplaceableItem> items = new ArrayList<ReplaceableItem>();
    ReplaceableItem item = new ReplaceableItem(collaborationId);
    item.withAttributes(
        new ReplaceableAttribute(
            COLLABORATION_ATTRIBUTE_PROCESS_DEFINITION_ID, processDeploymentId, true));

    items.add(item);

    sdb.batchPutAttributes(new BatchPutAttributesRequest(DOMAIN_COLLABORATION, items));

    logger.debug(LOGPRE + "setProcessDeploymentId() end" + LOGPRE);
  }
Ejemplo n.º 14
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#putDataIntoDomain(java.lang.Object)
   */
  public void putDataIntoDomain(Object object) {
    logger.debug(LOGPRE + "putDataIntoDomain() start" + LOGPRE);

    if (object instanceof Participant) {
      Participant participant = (Participant) object;
      List<ReplaceableItem> items = new ArrayList<ReplaceableItem>();
      items.add(
          new ReplaceableItem(participant.getId())
              .withAttributes(
                  new ReplaceableAttribute(PARTICIPANT_ATTRIBUTE_NAME, participant.getName(), true),
                  new ReplaceableAttribute(
                      PARTICIPANT_ATTRIBUTE_EMAIL, participant.getEmail(), true),
                  new ReplaceableAttribute(
                      PARTICIPANT_ATTRIBUTE_COLLABORATION_ID,
                      participant.getCollaborationId(),
                      false),
                  new ReplaceableAttribute(
                      PARTICIPANT_ATTRIBUTE_IS_REG, participant.getIsReg(), true)));

      logger.info("Putting participant <" + participant.getName() + "> into domain...");
      sdb.batchPutAttributes(new BatchPutAttributesRequest(DOMAIN_PARTICIPANT, items));
    }

    if (object instanceof Creator) {
      Creator creator = (Creator) object;
      if (!isCreatorExist(creator.getName())) {
        List<ReplaceableItem> items = new ArrayList<ReplaceableItem>();
        items.add(
            new ReplaceableItem(creator.getId())
                .withAttributes(
                    new ReplaceableAttribute(CREATOR_ATTRIBUTE_NAME, creator.getName(), true),
                    new ReplaceableAttribute(
                        CREATOR_ATTRIBUTE_PASSWORD, creator.getPassword(), true),
                    new ReplaceableAttribute(CREATOR_ATTRIBUTE_EMAIL, creator.getEmail(), true)));

        logger.info("Putting creator <" + creator.getName() + "> into domain...");
        sdb.batchPutAttributes(new BatchPutAttributesRequest(DOMAIN_CREATOR, items));
      }
    }

    if (object instanceof Collaboration) {
      Collaboration collaboration = (Collaboration) object;

      if (!isCollaborationExist(collaboration.getName())) {
        List<ReplaceableItem> items = new ArrayList<ReplaceableItem>();
        ReplaceableItem item = new ReplaceableItem(collaboration.getId());
        item.withAttributes(
            new ReplaceableAttribute(COLLABORATION_ATTRIBUTE_NAME, collaboration.getName(), true),
            new ReplaceableAttribute(
                COLLABORATION_ATTRIBUTE_CREATOR_ID, collaboration.getCreatorId(), true),
            new ReplaceableAttribute(
                COLLABORATION_ATTRIBUTE_CURRENT_STATE, collaboration.getCurrentState(), true),
            new ReplaceableAttribute(
                COLLABORATION_ATTRIBUTE_WORKFLOW_MODEL, collaboration.getWorkflowModel(), true));

        List<Participant> participants = collaboration.getParticipants();
        for (Participant participant : participants)
          item.withAttributes(
              new ReplaceableAttribute(
                  COLLABORATION_ATTRIBUTE_PARTICIPANT, participant.getName(), true));

        items.add(item);

        logger.info("Putting collaboration <" + collaboration.getName() + "> into domain...");
        sdb.batchPutAttributes(new BatchPutAttributesRequest(DOMAIN_COLLABORATION, items));
      }
    }

    logger.debug(LOGPRE + "putDataIntoDomain() end" + LOGPRE);
  }