Esempio n. 1
0
 @Test
 public void testSubQuery_oid() {
   String query =
       "Environment[@_oid =& Environment[@_status =& ApplicationService{@_status}.(services[@name=~\"srp-app.*\"] && updateStrategies[@name=\"1-100\"])]{@_oid} ]";
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertTrue(result.getEntities().size() == 1);
 }
Esempio n. 2
0
 /** When projection is a reference. */
 @Test
 public void testSub_CMS3430() {
   String query = "Environment.applications[@services=& ApplicationService{@services}]";
   raptorContext.setAllowFullTableScan(true);
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertEquals(1, result.getEntities().size());
 }
Esempio n. 3
0
 @Test
 public void testSubQuery_embed() {
   String query =
       "Dep.team[@_oid =& Dep[@_oid=~\"dep00[01]\"].team{@_oid}.person[@_oid=\"Dep!dep000!team!team010!person!person012\"] and @label=\"stratus\"]{*}";
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertEquals(1, result.getEntities().size());
 }
Esempio n. 4
0
  // Get the list of InstallableUnits and all its requirements
  protected List<IServerExtension> getInstallableUnits(
      IMetadataRepository repo, IQuery<IInstallableUnit> query, URI url, IProgressMonitor monitor) {
    List<IServerExtension> list = new ArrayList<IServerExtension>();
    IQueryResult<IInstallableUnit> collector = repo.query(query, monitor);

    for (IInstallableUnit iu : collector.toUnmodifiableSet()) {
      Collection<IRequirement> req = iu.getRequirements();
      if (req != null) {
        for (IRequirement requirement : req) {
          IMatchExpression<IInstallableUnit> matches = requirement.getMatches();
          query = new ExpressionMatchQuery<IInstallableUnit>(IInstallableUnit.class, matches);

          IQueryResult<IInstallableUnit> collector2 = repo.query(query, monitor);
          Iterator<IInstallableUnit> iter2 = collector2.iterator();
          while (iter2.hasNext()) {
            IInstallableUnit iu2 = iter2.next();
            if (!list.contains(iu2)) {
              Extension ext = new Extension(iu2, url);
              list.add(ext);
            }
          }
        }
      }
    }
    return list;
  }
Esempio n. 5
0
 @Test
 public void testSub05NonRef_aggregationFunc() {
   raptorContext.setAllowFullTableScan(true);
   String query =
       "Environment.applications[@services.$_length =& ApplicationService<@_type>{$count()}]";
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertEquals(0, result.getEntities().size());
 }
Esempio n. 6
0
 /** Hint issue */
 @Test
 public void testSub_CMS3430_2() {
   String query = "Asset[@_oid =& Rack{@assets}]";
   cmsdbContext.setAllowFullTableScan(true);
   cmsdbContext.setHint(1); // ## hint handling
   IQueryResult result = queryService.query(query, cmsdbContext);
   Assert.assertEquals(7, result.getEntities().size());
 }
Esempio n. 7
0
 @Test
 public void testSub05NonRef_aggregationField() {
   QueryContext context = new QueryContext(raptorContext);
   context.setAllowFullTableScan(true);
   context.clearMetadataServices();
   String query = "Environment.applications[@_type =& ApplicationService<@_type>{$max(@_type)}]";
   IQueryResult result = queryService.query(query, context);
   Assert.assertEquals(1, result.getEntities().size());
 }
Esempio n. 8
0
 @Test
 public void testSubQuery_selfAggregate_groupField() {
   String query = "Vlan[@resourceId =& Vlan<@resourceId>{@resourceId}]";
   QueryContext context = new QueryContext(cmsdbContext);
   context.clearMetadataServices();
   context.setAllowFullTableScan(true);
   IQueryResult result = queryService.query(query, context);
   Assert.assertEquals(1, result.getEntities().size());
 }
Esempio n. 9
0
 @Test
 public void testSub04WithSetUnionNot() {
   String query =
       "Environment[not @applications =& ApplicationService{*}.(services[@name=~\"srp-app.*\"] || updateStrategies[@name=\"1-100\"])]";
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertNotNull(result);
   Assert.assertNotNull(result.getEntities());
   Assert.assertTrue(result.getEntities().size() == 0);
 }
Esempio n. 10
0
 @Test
 public void testSubQuery_countonlyMoreSub() {
   String query = "ServiceInstance[ not @runsOn =& Compute{@_oid}.runsOn!ServiceInstance ]{*}";
   QueryContext qc = newQueryContext(raptorContext);
   qc.setCountOnly(true);
   qc.setMaxFetch(100);
   IQueryResult result = queryService.query(query, qc);
   Assert.assertEquals(2, result.getCount());
 }
Esempio n. 11
0
 @Test
 public void testSub04WithSetUnion2() {
   // query string that has update strategy with non-existing name
   String query =
       "Environment[@applications =& ApplicationService{*}.(services[@name=~\"srp-app.*\"] && updateStrategies[@name=\"1-30-100\"])]";
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertNotNull(result);
   Assert.assertNotNull(result.getEntities());
   Assert.assertTrue(result.getEntities().size() == 0);
 }
Esempio n. 12
0
 @Test
 public void testSub05NonRefType() {
   String query =
       "Environment[@_status =& ApplicationService{@_type}.(services[@name=~\"srp-app.*\"] && updateStrategies[@name=\"1-100\"])]";
   raptorContext.setAllowFullTableScan(true);
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertNotNull(result);
   Assert.assertNotNull(result.getEntities());
   Assert.assertTrue(result.getEntities().size() == 0);
 }
Esempio n. 13
0
 @Test
 public void testSub04_CMS3477_2() {
   String query =
       "ApplicationService[@services =& ServiceInstance{@_oid}.(services!ApplicationService[@name=~\"^srp-app:Raptor.*\"/s] &&(appService[@name=\"XXXXXX\"] || runsOn[@name=\"compute-00002\"])) and not exists @updateStrategies]{*}";
   raptorContext.setAllowFullTableScan(false);
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertNotNull(result);
   Assert.assertNotNull(result.getEntities());
   Assert.assertEquals(0, result.getEntities().size());
 }
Esempio n. 14
0
 @Test
 public void testSub05NonRef_aggregationField_01() {
   QueryContext context = new QueryContext(raptorContext);
   context.clearMetadataServices();
   context.setAllowFullTableScan(true);
   String query =
       "ServiceInstance[@port =& ServiceInstance<@healthStatus>[@healthStatus=\"unknown\"]{$max(@port)}]";
   IQueryResult result = queryService.query(query, context);
   Assert.assertEquals(1, result.getEntities().size());
 }
Esempio n. 15
0
 @Test
 public void testSub04_CMS3477_1() {
   String query =
       "ApplicationService[@services =& ApplicationService[@name=~\"^srp-app:Raptor.*\"/s].(services[@_oid=~\"XXXXXX\"]{@_oid} || updateStrategies[@name=~\"1-.*\"])]{*}";
   raptorContext.setAllowFullTableScan(false);
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertNotNull(result);
   Assert.assertNotNull(result.getEntities());
   Assert.assertEquals(0, result.getEntities().size());
 }
Esempio n. 16
0
 /** CMS-2935 */
 @Test
 public void testSub_CMS2935_03() {
   String query =
       "ServiceInstance[@_oid =& ServiceInstance[@name=~\"srp-app.*\"]{@_oid}.runsOn[@name=\"compute-00002\"]]";
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertNotNull(result);
   Assert.assertNotNull(result.getEntities());
   Assert.assertEquals(1, result.getEntities().size());
   for (IEntity entity : result.getEntities()) {
     Assert.assertEquals("ServiceInstance", entity.getType());
   }
 }
Esempio n. 17
0
  @Test
  public void testSub01NestedNot() {
    String sub =
        "ApplicationService[@name =~\"srp.*\" "
            + "and not "
            + " @services =& ServiceInstance"
            + "]";

    IQueryResult result = queryService.query(sub, raptorContext);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getEntities());
    Assert.assertEquals(0, result.getEntities().size());
  }
Esempio n. 18
0
  @Test
  public void testSub_CMS2935_02() {
    String query =
        "Environment[@applications =& ServiceInstance.(appService{*} && runsOn[@_oid=\"4fbb314fc681caf13e283a7b\"])]";
    IQueryResult result = queryService.query(query, raptorContext);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getEntities());
    Assert.assertTrue(result.getEntities().size() == 1);

    for (IEntity entity : result.getEntities()) {
      Assert.assertEquals("Environment", entity.getType());
    }
  }
Esempio n. 19
0
 @Test
 public void testSub05NonRef() {
   // sub query on non-
   String query =
       "Environment[@_status =& ApplicationService{@_status}.(services[@name=~\"srp-app.*\"] && updateStrategies[@name=\"1-100\"])]";
   raptorContext.setAllowFullTableScan(true);
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertNotNull(result);
   Assert.assertNotNull(result.getEntities());
   Assert.assertTrue(result.getEntities().size() == 1);
   for (IEntity entity : result.getEntities()) {
     Assert.assertEquals("Environment", entity.getType());
   }
 }
Esempio n. 20
0
  @Test
  public void testSub02Multi() {
    String sub =
        "ApplicationService[@name =~\"srp.*\""
            + " and "
            + "(@services =& ServiceInstance[@_oid=\"4fbb314fc681caf13e283a7c\" "
            + "                                 and @runsOn =& Compute[@name=\"compute-00002\"]])"
            + " and "
            + "@updateStrategies =& UpdateStrategy[@name=\"1-100\"]"
            + "]";

    IQueryResult result = queryService.query(sub, raptorContext);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getEntities());
    Assert.assertTrue(result.getEntities().size() == 1);
  }
Esempio n. 21
0
  @Test
  public void testSub03() {
    String sub =
        "ServiceInstance[@name=~\"srp-app.*\" and @runsOn =& Compute[@name=~\"compute-0000.*\"]]";

    IQueryResult result = queryService.query(sub, raptorContext);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getEntities());
    Assert.assertEquals(8, result.getEntities().size());

    // the service instance that have no compute attached
    String notIn1 = "4fbb314fc681caf13e283a7a";
    // the service instance that have compute name as compute-00010 (not match the regex).
    String notIn2 = "4fbb314fc681caf13e283a8c";
    for (IEntity entity : result.getEntities()) {
      Assert.assertEquals("ServiceInstance", entity.getType());
      Assert.assertFalse(entity.getId().equals(notIn1));
      Assert.assertFalse(entity.getId().equals(notIn2));
    }
  }
Esempio n. 22
0
  @Test
  public void testSub05NonRef_fieldProperty() {
    MetaClass metaClass = raptorMetaService.getMetaClass("ApplicationService");
    IEntity newApp = new JsonEntity(metaClass);
    newApp.setBranchId(IBranch.DEFAULT_BRANCH);
    newApp.addFieldValue("name", generateRandomName("cms3430-test"));

    EntityContext context = newEntityContext();
    String id = entityService.create(newApp, context);
    newApp.setId(id);

    String query =
        "Environment.applications[@services.$_length =& ApplicationService{@services.$_length}]";
    raptorContext.setHint(-1);
    raptorContext.setAllowFullTableScan(true);
    IQueryResult result = queryService.query(query, raptorContext);
    Assert.assertEquals(1, result.getEntities().size());

    entityService.delete(newApp, context);
  }
Esempio n. 23
0
 @Test
 public void testSubQuery_danglingCheck03() {
   String query = "ServiceInstance[ not @runsOn =& Compute{@_oid} ]{*}";
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertEquals(2, result.getEntities().size());
 }
Esempio n. 24
0
 @Test
 public void testSubQuery_danglingCheck() {
   String query = "ApplicationService[not @services =& ServiceInstance{@_oid}]{*}";
   IQueryResult result = queryService.query(query, raptorContext);
   Assert.assertEquals(0, result.getEntities().size());
 }