Ejemplo n.º 1
0
  @Test(enabled = ENABLE_TESTS)
  public void testDriftDef() throws Exception {
    Configuration config = new Configuration();
    DriftDefinition driftDefPojo = new DriftDefinition(config);
    driftDefPojo.setName("testDriftDef");
    driftDefPojo.setInterval(60L);
    driftDefPojo.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem, "foo/bar"));

    driftManager.updateDriftDefinition(
        overlord, EntityContext.forResource(newResource.getId()), driftDefPojo);

    ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
    ResourceCriteria c = new ResourceCriteria();
    c.addFilterId(newResource.getId());
    c.fetchDriftDefinitions(true);
    List<Resource> resources = resourceManager.findResourcesByCriteria(overlord, c);
    assertEquals(1, resources.size());
    Set<DriftDefinition> driftDefs = resources.get(0).getDriftDefinitions();
    assertNotNull(driftDefs);
    assertEquals(3, driftDefs.size());
    DriftDefinition driftDef = null;
    for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext(); ) {
      driftDef = i.next();
      if (driftDefPojo.getName().equals(driftDef.getName())) break;
    }
    assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
    assertEquals(driftDefPojo.getName(), driftDef.getName());
    assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
    assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());

    driftDefPojo.setInterval(120L);
    driftManager.updateDriftDefinition(
        overlord, EntityContext.forResource(newResource.getId()), driftDefPojo);

    resources = resourceManager.findResourcesByCriteria(overlord, c);
    assertEquals(1, resources.size());
    driftDefs = resources.get(0).getDriftDefinitions();
    assertNotNull(driftDefs);
    assertEquals(3, driftDefs.size());
    driftDef = null;
    for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext(); ) {
      driftDef = i.next();
      if (driftDefPojo.getName().equals(driftDef.getName())) break;
    }
    assertEquals(driftDefPojo.getName(), driftDef.getName());
    assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
    assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
    assertEquals(120L, driftDef.getInterval());

    driftDefPojo.setName("testDriftDef-2");
    driftDefPojo.setInterval(30L);
    driftDefPojo.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem, "foo/baz"));

    driftManager.updateDriftDefinition(
        overlord, EntityContext.forResource(newResource.getId()), driftDefPojo);

    resources = resourceManager.findResourcesByCriteria(overlord, c);
    assertEquals(1, resources.size());
    driftDefs = resources.get(0).getDriftDefinitions();
    assertNotNull(driftDefs);
    assertEquals(4, driftDefs.size());
    for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext(); ) {
      driftDef = i.next();
      if ("testDriftDef".equals(driftDef.getName())) {
        assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
        assertEquals("foo/bar", driftDef.getBasedir().getValueName());
        assertEquals(BaseDirValueContext.fileSystem, driftDef.getBasedir().getValueContext());
        assertEquals(120L, driftDef.getInterval());
      } else if ("testDriftDef-2".equals(driftDef.getName())) {
        assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
        assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
        assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());
      } else if (!"test-1".equals(driftDef.getName()) && !"test-2".equals(driftDef.getName())) {
        fail("Unexpected drift def name: " + driftDef.getName());
      }
    }

    driftManager.deleteDriftDefinition(
        overlord, EntityContext.forResource(newResource.getId()), "testDriftDef");
    resources = resourceManager.findResourcesByCriteria(overlord, c);
    assertEquals(1, resources.size());
    driftDefs = resources.get(0).getDriftDefinitions();
    assertNotNull(driftDefs);
    assertEquals(3, driftDefs.size());
    for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext(); ) {
      driftDef = i.next();
      if (driftDefPojo.getName().equals(driftDef.getName())) break;
    }
    assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
    assertEquals(driftDefPojo.getName(), driftDef.getName());
    assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
    assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());
  }
Ejemplo n.º 2
0
  @Test
  public void testDriftDef() throws Exception {
    Configuration config = new Configuration();
    DriftDefinition driftDefPojo = new DriftDefinition(config);
    driftDefPojo.setName("testDriftDef");
    driftDefPojo.setInterval(60L);
    driftDefPojo.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem, "foo/bar"));

    driftManager.updateDriftDefinition(
        overlord, EntityContext.forResource(newResource.getId()), driftDefPojo);

    DriftDefinitionCriteria c = new DriftDefinitionCriteria();
    c.addFilterResourceIds(newResource.getId());
    c.fetchConfiguration(true);
    List<DriftDefinition> driftDefs = driftManager.findDriftDefinitionsByCriteria(overlord, c);
    assertNotNull(driftDefs);
    assertEquals(3, driftDefs.size());
    DriftDefinition driftDef = null;
    for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext(); ) {
      driftDef = i.next();
      if (driftDefPojo.getName().equals(driftDef.getName())) break;
    }
    assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
    assertEquals(driftDefPojo.getName(), driftDef.getName());
    assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
    assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());

    driftDefPojo.setInterval(120L);
    driftManager.updateDriftDefinition(
        overlord, EntityContext.forResource(newResource.getId()), driftDefPojo);

    driftDefs = driftManager.findDriftDefinitionsByCriteria(overlord, c);
    assertNotNull(driftDefs);
    assertEquals(3, driftDefs.size());
    driftDef = null;
    for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext(); ) {
      driftDef = i.next();
      if (driftDefPojo.getName().equals(driftDef.getName())) break;
    }
    assertEquals(driftDefPojo.getName(), driftDef.getName());
    assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
    assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
    assertEquals(120L, driftDef.getInterval());

    driftDefPojo = new DriftDefinition(driftDef.getConfiguration().deepCopyWithoutProxies());
    driftDefPojo.setName("testDriftDef-2");
    driftDefPojo.setInterval(30L);
    driftDefPojo.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem, "foo/baz"));

    driftManager.updateDriftDefinition(
        overlord, EntityContext.forResource(newResource.getId()), driftDefPojo);

    driftDefs = driftManager.findDriftDefinitionsByCriteria(overlord, c);
    assertNotNull(driftDefs);
    assertEquals(4, driftDefs.size());
    for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext(); ) {
      driftDef = i.next();
      if ("testDriftDef".equals(driftDef.getName())) {
        assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
        assertEquals("foo/bar", driftDef.getBasedir().getValueName());
        assertEquals(BaseDirValueContext.fileSystem, driftDef.getBasedir().getValueContext());
        assertEquals(120L, driftDef.getInterval());
      } else if ("testDriftDef-2".equals(driftDef.getName())) {
        assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
        assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
        assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());
      } else if (!"test-1".equals(driftDef.getName()) && !"test-2".equals(driftDef.getName())) {
        fail("Unexpected drift def name: " + driftDef.getName());
      }
    }

    driftManager.deleteDriftDefinition(
        overlord, EntityContext.forResource(newResource.getId()), "testDriftDef");
    driftDefs = driftManager.findDriftDefinitionsByCriteria(overlord, c);
    assertNotNull(driftDefs);
    assertEquals(3, driftDefs.size());
    for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext(); ) {
      driftDef = i.next();
      if (driftDefPojo.getName().equals(driftDef.getName())) break;
    }
    assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
    assertEquals(driftDefPojo.getName(), driftDef.getName());
    assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
    assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());
  }
  private void assertVersion2(ResourceType resourceType) {
    PropertyDefinition prop;
    Set<String> seen =
        new HashSet<String>(2); // we use to this remember names of the things that we've seen

    assert resourceType.getChildSubCategories().size() == 1;
    assert resourceType.getChildSubCategories().get(0).getName().equals(SUBCAT);
    assert resourceType.getChildSubCategories().get(0).getDisplayName().equals(SUBCAT_DISPLAYNAME);

    seen.clear();
    ConfigurationDefinition pcDef = resourceType.getPluginConfigurationDefinition();
    assert pcDef.getGroupDefinitions().size() == 2;
    for (PropertyGroupDefinition group : pcDef.getGroupDefinitions()) {
      seen.add(group.getName());
      if (group.getName().equals(CHANGED_PC_GROUP)) {
        assert group.isDefaultHidden() == CHANGED_PC_GROUP_HIDDEN;
      } else if (group.getName().equals(NEW_PC_GROUP)) {
        assert group.isDefaultHidden() == NEW_PC_GROUP_HIDDEN;
      } else {
        assert false : "Unexpected group [" + group.getName() + "]:" + group;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }

    prop = pcDef.get(CHANGED_PC_PROP);
    assert prop != null;
    assert prop.getName().equals(CHANGED_PC_PROP);
    assert prop.isRequired() == CHANGED_PC_PROP_REQUIRED;
    assert prop.getPropertyGroupDefinition().getName().equals(CHANGED_PC_GROUP);
    prop = pcDef.get(NEW_PC_PROP);
    assert prop != null;
    assert prop.getName().equals(NEW_PC_PROP);
    assert prop.isRequired() == NEW_PC_PROP_REQUIRED;
    assert prop.getPropertyGroupDefinition().getName().equals(NEW_PC_GROUP);

    seen.clear();
    assert resourceType.getProcessScans().size() == 2;
    for (ProcessScan processScan : resourceType.getProcessScans()) {
      seen.add(processScan.getName());
      if (processScan.getName().equals(CHANGED_PROCESS_SCAN_NAME)) {
        assert processScan.getQuery().equals(CHANGED_PROCESS_SCAN_QUERY);
      } else if (processScan.getName().equals(NEW_PROCESS_SCAN_NAME)) {
        assert processScan.getQuery().equals(NEW_PROCESS_SCAN_QUERY);
      } else {
        assert false : "Unexpected process scan[" + processScan.getName() + "]:" + processScan;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }

    seen.clear();
    assert resourceType.getOperationDefinitions().size() == 2;
    for (OperationDefinition op : resourceType.getOperationDefinitions()) {
      seen.add(op.getName());
      if (op.getName().equals(CHANGED_OP_NAME)) {
        assert op.getTimeout().intValue() == CHANGED_OP_TIMEOUT;
        assert op.getDescription().equals(CHANGED_OP_DESC);
      } else if (op.getName().equals(NEW_OP_NAME)) {
        assert op.getTimeout().intValue() == NEW_OP_TIMEOUT;
        assert op.getDescription().equals(NEW_OP_DESC);
      } else {
        assert false : "Unexpected operation [" + op.getName() + "]:" + op;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }

    seen.clear();
    assert resourceType.getMetricDefinitions().size() == 3; // include built-in Availability metric
    for (MeasurementDefinition metric : resourceType.getMetricDefinitions()) {
      if (metric.getName().equals(MeasurementDefinition.AVAILABILITY_NAME)) {
        // expected, ignore
        continue;
      }

      seen.add(metric.getName());
      if (metric.getName().equals(CHANGED_METRIC_PROP)) {
        // even though our _v2 plugin set this to something different, our upgrade doesn't change it
        // because
        // we don't want to overwrite changes a user possibly made to the defaut interval (aka
        // metric template)
        assert metric.getDefaultInterval() == METRIC_DEFAULT_INTERVAL;
      } else if (metric.getName().equals(NEW_METRIC_PROP)) {
        assert metric.getDefaultInterval() == NEW_METRIC_DEFAULT_INTERVAL;
      } else {
        assert false : "Unexpected metric [" + metric.getName() + "]:" + metric;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }

    seen.clear();
    assert resourceType.getEventDefinitions().size() == 2;
    for (EventDefinition event : resourceType.getEventDefinitions()) {
      seen.add(event.getName());
      if (event.getName().equals(CHANGED_EVENT_NAME)) {
        assert event.getDescription().equals(CHANGED_EVENT_DESC);
      } else if (event.getName().equals(NEW_EVENT_NAME)) {
        assert event.getDescription().equals(NEW_EVENT_DESC);
      } else {
        assert false : "Unexpected event [" + event.getName() + "]:" + event;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }

    assert resourceType.getResourceConfigurationDefinition().getGroupDefinitions().size() == 0;
    prop = resourceType.getResourceConfigurationDefinition().get(CHANGED_RC_PROP);
    assert prop != null;
    assert prop.getName().equals(CHANGED_RC_PROP);
    assert prop.isRequired() == CHANGED_RC_PROP_REQUIRED;
    prop = resourceType.getResourceConfigurationDefinition().get(NEW_RC_PROP);
    assert prop != null;
    assert prop.getName().equals(NEW_RC_PROP);
    assert prop.isRequired() == NEW_RC_PROP_REQUIRED;

    seen.clear();
    assert resourceType.getDriftDefinitionTemplates().size() == 2;
    for (DriftDefinitionTemplate drift : resourceType.getDriftDefinitionTemplates()) {
      DriftDefinition def = drift.getTemplateDefinition();
      seen.add(def.getName());
      if (def.getName().equals(CHANGED_DRIFT_DEF_NAME)) {
        BaseDirectory driftBasedir = def.getBasedir();
        assert driftBasedir.getValueContext().equals(CHANGED_DRIFT_DEF_BASEDIR_CONTEXT);
        assert driftBasedir.getValueName().equals(CHANGED_DRIFT_DEF_BASEDIR_VALUE);
      } else if (def.getName().equals(NEW_DRIFT_DEF_NAME)) {
        BaseDirectory driftBasedir = def.getBasedir();
        assert driftBasedir.getValueContext().equals(NEW_DRIFT_DEF_BASEDIR_CONTEXT);
        assert driftBasedir.getValueName().equals(NEW_DRIFT_DEF_BASEDIR_VALUE);
      } else {
        assert false : "Unexpected drift def [" + def.getName() + "]:" + def;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }

    seen.clear();
    ResourceTypeBundleConfiguration bundle = resourceType.getResourceTypeBundleConfiguration();
    assert bundle.getBundleDestinationBaseDirectories().size() == 2;
    for (BundleDestinationBaseDirectory bundleBasedir :
        bundle.getBundleDestinationBaseDirectories()) {
      seen.add(bundleBasedir.getName());
      if (bundleBasedir.getName().equals(CHANGED_BUNDLE_TARGET_NAME)) {
        assert bundleBasedir.getValueContext().equals(CHANGED_BUNDLE_BASEDIR_CONTEXT);
        assert bundleBasedir.getValueName().equals(CHANGED_BUNDLE_BASEDIR_VALUE);
      } else if (bundleBasedir.getName().equals(NEW_BUNDLE_TARGET_NAME)) {
        assert bundleBasedir.getValueContext().equals(NEW_BUNDLE_BASEDIR_CONTEXT);
        assert bundleBasedir.getValueName().equals(NEW_BUNDLE_BASEDIR_VALUE);
      } else {
        assert false
            : "Unexpected bundle basedir [" + bundleBasedir.getName() + "]:" + bundleBasedir;
      }
    }
    if (seen.size() != 2) {
      assert false : "did not see what we expected to see: " + seen;
    }
  }