Exemplo n.º 1
0
  private void findApplication() {
    SesameSPARQLClient sparqlCl = null;
    try {
      sparqlCl = new SesameSPARQLClient();
    } catch (RepositoryException e) {
      logger.error("Init sparql repository error. ", e);
      return;
    }

    oamo = new OAMO();

    TupleQueryResult qres =
        sparqlCl.sparqlToQResult(Queries.getRootOAMOData(lsmFunctionalGraph, oamoID));
    Queries.RootOAMOData rootOAMODATA = Queries.parseOAMORootData(qres);

    oamo.setName(rootOAMODATA.getOamoName());
    oamo.setId(rootOAMODATA.getUserID());
    oamo.setDescription(rootOAMODATA.getOamoDesc());
    oamo.setGraphMeta(rootOAMODATA.getOamoGraphMeta());

    qres = sparqlCl.sparqlToQResult(Queries.getOSMOListOfOAMO(lsmFunctionalGraph, oamoID));
    ArrayList<Queries.RootOsmoData> OSMODataList = Queries.parseOSMOListOfOAMO(qres);

    for (Queries.RootOsmoData osmodata : OSMODataList) {

      GetServiceImpl service = new GetServiceImpl(osmodata.getId());
      OSMO osmo = service.getService();

      oamo.getOSMO().add(osmo);
    }
  }
  /*
   * This method updates a particular users details in the users table
   * based on the id of the user
   */
  public void updateDeatils(
      String id, String fname, String lname, String add, String email, String phone) {
    try {
      q.open();
      String sql =
          "UPDATE Users SET First_Name = '"
              + fname
              + "', Last_Name = '"
              + lname
              + "', HomeAddress = '"
              + add
              + "',Email_Address = '"
              + email
              + "',Phone_Number = "
              + phone
              + "WHERE User_ID = '"
              + id
              + "'";

      stmt = q.getConn().createStatement();
      stmt.executeUpdate(sql);

      System.out.println("Users deatils have been updated");
    } catch (Exception e) {
      System.out.println("Update details error" + e);
    }
    q.close();
  }
  public void processHostData() {
    try {

      PreparedStatement pstmt = sqlConnection.prepareStatement(Queries.getSqlInsertHostInfo());
      AggregationOutput aggregationOutput =
          mongoTask.getAggregatedOutput("host", Queries.getHostInfoQuery());
      for (DBObject obj : aggregationOutput.results()) {
        String hostname = (String) obj.get("hostname");
        Double cpuUsage = Double.parseDouble(obj.get("cpuusage").toString());
        Double cpuMax = Double.parseDouble(obj.get("cpumax").toString());
        Double cpuPercent = Double.parseDouble(obj.get("cpupercentage").toString());
        Double memUsage = Double.parseDouble(obj.get("memusage").toString());
        Double memMax = Double.parseDouble(obj.get("memmax").toString());
        Double memPercent = Double.parseDouble(obj.get("mempercentage").toString());
        Double upTime = Double.parseDouble(obj.get("uptime").toString());
        Double tx = Double.parseDouble(obj.get("tx").toString());
        Double rx = Double.parseDouble(obj.get("rx").toString());
        pstmt.setTimestamp(1, new java.sql.Timestamp(timeStamp.getTime()));
        pstmt.setString(2, hostname);
        pstmt.setDouble(3, cpuUsage);
        pstmt.setDouble(4, cpuMax);
        pstmt.setDouble(5, cpuPercent);
        pstmt.setDouble(6, memUsage);
        pstmt.setDouble(7, memMax);
        pstmt.setDouble(8, memPercent);
        pstmt.setDouble(9, upTime);
        pstmt.setDouble(10, tx);
        pstmt.setDouble(11, rx);
        pstmt.addBatch();
      }
      pstmt.executeBatch();
    } catch (SQLException s) {
      s.printStackTrace();
    }
  }
Exemplo n.º 4
0
  // MMB-1889
  public void testCreateRelationAndDeleteNode() {
    // Make a relation to an existing node. Then delete that node with the 'delete relations'
    // option'. Commit the transaction.
    // The new relations should not exist, since the node was deleted.
    // No errors.

    Cloud cloud = getCloud();

    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());
    int relCount = Queries.count(cloud.getNodeManager("insrel").createQuery());

    Node url = cloud.getNodeManager("urls").createNode();
    url.commit();

    Transaction t = cloud.getTransaction("relatedandelete");

    Node turl = t.getNode(url.getNumber());
    Node news = t.getNode(newNode);
    RelationManager rm = t.getRelationManager("urls", "news", "posrel");
    Relation r = turl.createRelation(news, rm);
    r.commit();
    turl.delete(true);
    t.commit();

    int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery());
    assertEquals(urlCount, urlCountAfter);
    int relCountAfter = Queries.count(cloud.getNodeManager("insrel").createQuery());
    assertEquals(relCount, relCountAfter);
  }
Exemplo n.º 5
0
  // MMB-1860 (4)
  public void testRelateAndDeleteRelation() {

    //  Make a relation between two nodes. Delete the relation again. Commit the transaction.
    // Te relation shouldn't exist

    Cloud cloud = getCloud();
    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());
    int relCount = Queries.count(cloud.getNodeManager("insrel").createQuery());

    Node newUrl = cloud.getNodeManager("urls").createNode();
    newUrl.commit();

    Transaction t = cloud.getTransaction("testrelateandeleterelation");

    Node news = t.getNode(newNode);
    Node url = t.getNode(newUrl.getNumber());
    RelationManager rm = t.getRelationManager("urls", "news", "posrel");
    Relation r = url.createRelation(news, rm);
    r.commit();

    r.delete();

    t.commit();

    int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery());

    assertEquals(urlCount + 1, urlCountAfter);

    // But the relation should not exist, because it was deleted angain

    int relCountAfter = Queries.count(cloud.getNodeManager("insrel").createQuery());

    assertEquals(relCount, relCountAfter);
  }
  public void processHostTaskData() {
    try {
      PreparedStatement pstmt = sqlConnection.prepareStatement(Queries.getSqlInsertHostTaskInfo());
      AggregationOutput aggregationOutput =
          mongoTask.getAggregatedOutput("task", Queries.getHostTaskInfoQuery());
      for (DBObject obj : aggregationOutput.results()) {
        String timeStamp = (String) obj.get("timestamp");
        String action = (String) obj.get("action");
        String target = (String) obj.get("target");
        double timeTaken = Double.parseDouble(obj.get("timeTaken").toString());

        pstmt.setTimestamp(
            1,
            new java.sql.Timestamp(
                MongoAggregationHelper.jsonDateFormat.parse(timeStamp).getTime()));
        pstmt.setString(2, target);
        pstmt.setString(3, action);
        pstmt.setDouble(4, timeTaken);
        pstmt.setInt(5, 1);
        pstmt.addBatch();
      }
      pstmt.executeBatch();
    } catch (SQLException | ParseException s) {
      s.printStackTrace();
    }
  }
Exemplo n.º 7
0
  public void testCreateAndDelete2() {
    // Create new node. Request the node again. Delete  that. Commit the transaction.
    // The new node must not exist.

    Cloud cloud = getCloud();
    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());

    Transaction t = cloud.getTransaction("testcreateandelete");
    Node url = t.getNodeManager("urls").createNode();
    url.commit();
    assertEquals(1, t.getNodes().size());

    Node reurl = t.getNode(url.getNumber());
    reurl.delete();

    assertEquals(
        1,
        t.getNodes()
            .size()); // 0 would also be an option, but the node remaisn in the transaction as
                      // 'NOLONGER'

    t.commit();

    int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery());

    assertEquals(urlCount, urlCountAfter);
  }
Exemplo n.º 8
0
  public static final ApplyChangesInfo deleteNotes(Context context, Collection<RtmTaskNote> notes) {
    boolean ok = true;
    ContentProviderActionItemList actionItemList = new ContentProviderActionItemList();

    for (Iterator<RtmTaskNote> i = notes.iterator(); ok && i.hasNext(); ) {
      final String noteId = i.next().getId();
      final ModificationSet modifications = new ModificationSet();

      modifications.add(
          Modification.newNonPersistentModification(
              Queries.contentUriWithId(Notes.CONTENT_URI, noteId),
              Notes.NOTE_DELETED,
              System.currentTimeMillis()));
      modifications.add(Modification.newNoteModified(noteId));

      ok =
          actionItemList.add(
              ContentProviderAction.Type.DELETE,
              CreationsProviderPart.deleteCreation(
                  Queries.contentUriWithId(Notes.CONTENT_URI, noteId)));
      actionItemList.add(modifications);
    }

    if (!ok) actionItemList = null;

    return new ApplyChangesInfo(
        actionItemList,
        context.getString(R.string.toast_delete_note),
        context.getString(R.string.toast_delete_note_ok),
        context.getString(R.string.toast_delete_note_failed));
  }
Exemplo n.º 9
0
 public void testAddToResultCreateOneRelation() {
   Node mag = getCloud().getNodeManager("mags").createNode();
   mag.commit();
   Node news = getCloud().getNodeManager("news").createNode();
   news.commit();
   NodeQuery q =
       Queries.createRelatedNodesQuery(
           mag, getCloud().getNodeManager("news"), "posrel", "destination");
   NodeList result = Queries.addToResult(q, news);
   assertEquals(1, result.size());
 }
  /*
   * This method updates a particular users password in the database
   */
  public void updatePassword(String id, String password) {
    try {
      q.open();
      String sql =
          "UPDATE Users SET UserPassword = '******' WHERE User_ID = '" + id + "'";

      stmt = q.getConn().createStatement();
      stmt.executeUpdate(sql);

      System.out.println("Users password have been updated");
    } catch (Exception e) {
      System.out.println("Update password error" + e);
    }
    q.close();
  }
Exemplo n.º 11
0
 public void testAddToResultCreateTwoRelations() {
   Node mag = getCloud().getNodeManager("mags").createNode();
   mag.commit();
   Node news = getCloud().getNodeManager("news").createNode();
   news.commit();
   Node url = getCloud().getNodeManager("urls").createNode();
   url.commit();
   NodeQuery q =
       Queries.createRelatedNodesQuery(
           mag, getCloud().getNodeManager("news"), "posrel", "destination");
   Queries.addPath(q, "posrel,urls", "destination");
   Queries.addStartNodes(q, "" + url.getNumber());
   NodeList result = Queries.addToResult(q, news);
   assertEquals(2, result.size());
 }
 @Override
 public Query rewrite(IndexReader reader) throws IOException {
   Query rewritten = super.rewrite(reader);
   if (rewritten != this) {
     return rewritten;
   }
   if (termArrays.isEmpty()) {
     return new MatchNoDocsQuery();
   }
   MultiPhraseQuery.Builder query = new MultiPhraseQuery.Builder();
   query.setSlop(slop);
   int sizeMinus1 = termArrays.size() - 1;
   for (int i = 0; i < sizeMinus1; i++) {
     query.add(termArrays.get(i), positions.get(i));
   }
   Term[] suffixTerms = termArrays.get(sizeMinus1);
   int position = positions.get(sizeMinus1);
   ObjectHashSet<Term> terms = new ObjectHashSet<>();
   for (Term term : suffixTerms) {
     getPrefixTerms(terms, term, reader);
     if (terms.size() > maxExpansions) {
       break;
     }
   }
   if (terms.isEmpty()) {
     return Queries.newMatchNoDocsQuery();
   }
   query.add(terms.toArray(Term.class), position);
   return query.build();
 }
Exemplo n.º 13
0
  @Test
  public void testVerifyAggregationsMissingVal() throws Exception {
    List<AggregatorFactory> aggFactories =
        Arrays.<AggregatorFactory>asList(
            new CountAggregatorFactory("count"),
            new DoubleSumAggregatorFactory("idx", "index"),
            new DoubleSumAggregatorFactory("rev", "revenue"));

    List<PostAggregator> postAggs =
        Arrays.<PostAggregator>asList(
            new ArithmeticPostAggregator(
                "addStuff",
                "+",
                Arrays.<PostAggregator>asList(
                    new FieldAccessPostAggregator("idx", "idx2"),
                    new FieldAccessPostAggregator("count", "count"))));

    boolean exceptionOccured = false;

    try {
      Queries.verifyAggregations(aggFactories, postAggs);
    } catch (IllegalArgumentException e) {
      exceptionOccured = true;
    }

    Assert.assertTrue(exceptionOccured);
  }
Exemplo n.º 14
0
  @Override
  public OperationResult run(Connection conn) throws SQLException {
    // First, find the user
    User user = Queries.getUser(conn, spec.getUsername(), this);
    if (user == null) {
      return new OperationResult(false, "Unknown user " + spec.getUsername());
    }

    // Create the CourseRegistration
    CourseRegistration reg = new CourseRegistration();
    reg.setUserId(user.getId());
    reg.setCourseId(spec.getCourseId());
    reg.setRegistrationType(spec.getRegistrationType());
    reg.setSection(spec.getSection());

    // Insert the CourseRegistration
    DBUtil.storeModelObject(conn, reg);

    Course course = null;
    try {
      course = DBUtil.loadModelObjectForId(conn, Course.SCHEMA, spec.getCourseId());
    } catch (NoSuchUniqueIdException e) {
      logger.error("Could not find course for id={}", spec.getCourseId());
    }

    return new OperationResult(
        true,
        "Added user "
            + spec.getUsername()
            + " to course"
            + (course != null ? " " + course.getNameAndTitle() : ""));
  }
Exemplo n.º 15
0
  public static final ApplyChangesInfo setNoteTitleAndText(
      Context context, String noteId, String title, String text) {
    final ModificationSet modifications = new ModificationSet();

    modifications.add(
        Modification.newModification(
            Queries.contentUriWithId(Notes.CONTENT_URI, noteId), Notes.NOTE_TITLE, title));
    modifications.add(
        Modification.newModification(
            Queries.contentUriWithId(Notes.CONTENT_URI, noteId), Notes.NOTE_TEXT, text));
    modifications.add(Modification.newNoteModified(noteId));

    return new ApplyChangesInfo(
        modifications.toContentProviderActionItemList(),
        context.getString(R.string.toast_save_note),
        context.getString(R.string.toast_save_note_ok),
        context.getString(R.string.toast_save_note_failed));
  }
 public void processVmCpuData() {
   try {
     PreparedStatement pstmt = sqlConnection.prepareStatement(Queries.getSqlInsertVmCpuInfo());
     AggregationOutput aggregationOutput =
         mongoTask.getAggregatedOutput("cpuinfo", Queries.getCpuInfoQuery());
     for (DBObject obj : aggregationOutput.results()) {
       String hostname = (String) obj.get("_id");
       double usage = Double.parseDouble(obj.get("usage").toString());
       pstmt.setTimestamp(1, new java.sql.Timestamp(timeStamp.getTime()));
       pstmt.setString(2, hostname);
       pstmt.setDouble(3, usage);
       pstmt.setInt(4, 1);
       pstmt.addBatch();
     }
     pstmt.executeBatch();
   } catch (SQLException s) {
     s.printStackTrace();
   }
 }
Exemplo n.º 17
0
  // MMB-1893
  public void testDeleteNodeWitRelationsAndCancel() {
    Cloud cloud = getCloud();

    int urlCount0 = Queries.count(cloud.getNodeManager("urls").createQuery());
    int relCount0 = Queries.count(cloud.getNodeManager("insrel").createQuery());

    Node url = cloud.getNodeManager("urls").createNode();
    url.commit();
    Node news = cloud.getNode(newNode);
    RelationManager rm = cloud.getRelationManager("urls", "news", "posrel");
    Relation r = url.createRelation(news, rm);
    r.commit();

    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());
    int relCount = Queries.count(cloud.getNodeManager("insrel").createQuery());

    assertEquals(urlCount0 + 1, urlCount);
    assertEquals(relCount0 + 1, relCount);

    Transaction t = cloud.getTransaction("deletewithrelationsandcancel");

    Node turl = t.getNode(url.getNumber());
    turl.delete(true);

    t.cancel();

    int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery());
    assertEquals(urlCount, urlCountAfter);

    int relCountAfter = Queries.count(cloud.getNodeManager("insrel").createQuery());
    assertEquals(relCount, relCountAfter); // MMB-1893
  }
 public void processVmNetworkData() {
   try {
     PreparedStatement pstmt = sqlConnection.prepareStatement(Queries.getSqlInsertVmNetInfo());
     AggregationOutput aggregationOutput =
         mongoTask.getAggregatedOutput("netinfo", Queries.getNetInfoQuery());
     for (DBObject obj : aggregationOutput.results()) {
       String hostname = ((BasicDBObject) obj.get("_id")).getString("hostname");
       String ninterface = ((BasicDBObject) obj.get("_id")).getString("interface");
       double rx = Double.parseDouble(obj.get("rx").toString());
       double tx = Double.parseDouble(obj.get("tx").toString());
       pstmt.setTimestamp(1, new java.sql.Timestamp(timeStamp.getTime()));
       pstmt.setString(2, hostname);
       pstmt.setString(3, ninterface);
       pstmt.setDouble(4, tx);
       pstmt.setDouble(5, rx);
       pstmt.setInt(6, 1);
       pstmt.addBatch();
     }
     pstmt.executeBatch();
   } catch (SQLException s) {
     s.printStackTrace();
   }
 }
Exemplo n.º 19
0
  // MMB-1860 (2)
  public void testCreateRelateAndDelete() {

    // Create new node. Make a relation to it. Delete the node again. Commit the transaction.
    // The new node must not exist, but the relation shouldn't have caused errors

    Cloud cloud = getCloud();
    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());

    Transaction t = cloud.getTransaction("testcreateandelete");

    Node news = t.getNode(newNode);
    Node url = t.getNodeManager("urls").createNode();
    RelationManager rm = t.getRelationManager("urls", "news", "posrel");
    Relation r = url.createRelation(news, rm);

    url.delete(true);

    t.commit();

    int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery());

    assertEquals(urlCount, urlCountAfter);
  }
 public void procesVmDiskIoData() {
   try {
     PreparedStatement pstmt = sqlConnection.prepareStatement(Queries.getSqlInsertVmDiskInfo());
     AggregationOutput aggregationOutput =
         mongoTask.getAggregatedOutput("diskio", Queries.getDiskIoQuery());
     for (DBObject obj : aggregationOutput.results()) {
       String hostname = ((BasicDBObject) obj.get("_id")).getString("hostname");
       String device = ((BasicDBObject) obj.get("_id")).getString("device");
       double read = Double.parseDouble(obj.get("read").toString());
       double write = Double.parseDouble(obj.get("write").toString());
       pstmt.setTimestamp(1, new java.sql.Timestamp(timeStamp.getTime()));
       pstmt.setString(2, hostname);
       pstmt.setString(3, device);
       pstmt.setDouble(4, read);
       pstmt.setDouble(5, write);
       pstmt.setInt(6, 1);
       pstmt.addBatch();
     }
     pstmt.executeBatch();
   } catch (SQLException s) {
     s.printStackTrace();
   }
 }
  public void rollUpData(Date startTime, Date endTime, int rollupStamp, int targetRollupStamp) {
    try {
      PreparedStatement pstmt =
          sqlConnection.prepareStatement(Queries.getSqlExecuteRollUpProcedure());
      pstmt.setTimestamp(1, new Timestamp(timeStamp.getTime()));
      pstmt.setTimestamp(2, new Timestamp(startTime.getTime()));
      pstmt.setTimestamp(3, new Timestamp(endTime.getTime()));
      pstmt.setInt(4, rollupStamp);
      pstmt.setInt(5, targetRollupStamp);
      pstmt.executeUpdate();

    } catch (SQLException s) {
      s.printStackTrace();
    }
  }
Exemplo n.º 22
0
  public void testGetNode() {
    // Create new node. Request the node again.
    // Should work

    Cloud cloud = getCloud();
    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());

    Transaction t = cloud.getTransaction("testgetnode");
    Node url = t.getNodeManager("urls").createNode();
    url.setStringValue("url", "http://bla");
    url.commit();

    Node reurl = t.getNode(url.getNumber());

    assertEquals("http://bla", reurl.getStringValue("url"));
  }
Exemplo n.º 23
0
  public static final ApplyChangesInfo insertNote(Context context, RtmTaskNote note) {
    ContentProviderActionItemList actionItemList = new ContentProviderActionItemList();

    boolean ok =
        actionItemList.add(
            ContentProviderAction.Type.INSERT, RtmNotesProviderPart.insertLocalCreatedNote(note));
    ok =
        ok
            && actionItemList.add(
                ContentProviderAction.Type.INSERT,
                CreationsProviderPart.newCreation(
                    Queries.contentUriWithId(Notes.CONTENT_URI, note.getId()),
                    note.getCreatedDate().getTime()));

    if (!ok) actionItemList = null;

    return new ApplyChangesInfo(
        actionItemList,
        context.getString(R.string.toast_insert_note),
        context.getString(R.string.toast_insert_note_ok),
        context.getString(R.string.toast_insert_note_fail));
  }
 @Override
 public List<UserAndSubmissionReceipt> run(Connection conn) throws SQLException {
   return Queries.doGetBestSubmissionReceipts(conn, problem, section, this);
 }