org.apache.brooklyn.api.policy.PolicySpec Java Examples
The following examples show how to use
org.apache.brooklyn.api.policy.PolicySpec.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceRestarterTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testDoesNotSetOnFireOnFailure() throws Exception { final FailingEntity e2 = app.createAndManageChild(EntitySpec.create(FailingEntity.class) .configure(FailingEntity.SET_SERVICE_DOWN_ON_FAILURE, false) .configure(FailingEntity.FAIL_ON_RESTART, true)); app.subscriptions().subscribe(e2, ServiceRestarter.ENTITY_RESTART_FAILED, eventListener); policy = e2.policies().add(PolicySpec.create(ServiceRestarter.class) .configure(ServiceRestarter.FAILURE_SENSOR_TO_MONITOR, HASensors.ENTITY_FAILED) .configure(ServiceRestarter.SET_ON_FIRE_ON_FAILURE, false)); e2.sensors().emit(HASensors.ENTITY_FAILED, new FailureDescriptor(e2, "simulate failure")); Asserts.succeedsContinually(new Runnable() { @Override public void run() { assertNotEquals(e2.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.ON_FIRE); }}); }
Example #2
Source File: MongoDBShardedDeploymentImpl.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Override public void start(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); try { final MongoDBRouterCluster routers = getAttribute(ROUTER_CLUSTER); final MongoDBShardCluster shards = getAttribute(SHARD_CLUSTER); List<DynamicCluster> clusters = ImmutableList.of(getAttribute(CONFIG_SERVER_CLUSTER), routers, shards); Entities.invokeEffectorList(this, clusters, Startable.START, ImmutableMap.of("locations", locations)) .get(); if (config().getRaw(MongoDBShardedDeployment.CO_LOCATED_ROUTER_GROUP).isPresent()) { policies().add(PolicySpec.create(ColocatedRouterTrackingPolicy.class) .displayName("Co-located router tracker") .configure("group", getConfig(MongoDBShardedDeployment.CO_LOCATED_ROUTER_GROUP))); } ServiceNotUpLogic.clearNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL); ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); } catch (Exception e) { ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE); // no need to log here; the effector invocation should do that throw Exceptions.propagate(e); } }
Example #3
Source File: HazelcastClusterImpl.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Override public void init() { super.init(); String clusterPassword = getClusterPassword(); if (Strings.isBlank(clusterPassword)) { if (LOG.isInfoEnabled()) { LOG.info(this + " cluster password not provided for " + CLUSTER_PASSWORD.getName() + " : generating random password"); } config().set(CLUSTER_PASSWORD, Identifiers.makeRandomPassword(12)); } policies().add(PolicySpec.create(MemberTrackingPolicy.class) .displayName("Hazelcast members tracker") .configure("group", this)); }
Example #4
Source File: MembershipTrackingPolicyTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testNotNotifiedOfExtraTrackedSensorsIfNonDuplicate() throws Exception { TestEntity e1 = createAndManageChildOf(group); app.policies().removeAllPolicies(); RecordingMembershipTrackingPolicy nonDuplicateTrackingPolicy = app.policies().add(PolicySpec.create(RecordingMembershipTrackingPolicy.class) .configure(AbstractMembershipTrackingPolicy.SENSORS_TO_TRACK, ImmutableSet.<Sensor<?>>of(TestEntity.NAME)) .configure(AbstractMembershipTrackingPolicy.NOTIFY_ON_DUPLICATES, false) .configure(AbstractMembershipTrackingPolicy.GROUP, group)); e1.sensors().set(TestEntity.NAME, "myname"); assertRecordsEventually(nonDuplicateTrackingPolicy, Record.newAdded(e1), Record.newChanged(e1)); e1.sensors().set(TestEntity.NAME, "myname"); assertRecordsContinually(nonDuplicateTrackingPolicy, Record.newAdded(e1), Record.newChanged(e1)); e1.sensors().set(TestEntity.NAME, "mynewname"); assertRecordsEventually(nonDuplicateTrackingPolicy, Record.newAdded(e1), Record.newChanged(e1), Record.newChanged(e1)); }
Example #5
Source File: RebindPolicyTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testPolicyAddedWhenEntityRelationshipsSet() throws Exception { BasicGroup origGroup = origApp.createAndManageChild(EntitySpec.create(BasicGroup.class)); TestEntity origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class)); origGroup.addMember(origEntity); EnricherChecksEntityHierarchy origEnricher = origApp.enrichers().add(EnricherSpec.create(EnricherChecksEntityHierarchy.class)); PolicyChecksEntityHierarchy origPolicy = origApp.policies().add(PolicySpec.create(PolicyChecksEntityHierarchy.class)); assertTrue(origEnricher.success); assertTrue(origPolicy.success); newApp = rebind(); EnricherChecksEntityHierarchy newEnricher = (EnricherChecksEntityHierarchy) Iterables.getOnlyElement(newApp.enrichers()); PolicyChecksEntityHierarchy newPolicy = (PolicyChecksEntityHierarchy) Iterables.getOnlyElement(newApp.policies()); assertTrue(newEnricher.success); assertTrue(newPolicy.success); }
Example #6
Source File: InvokeEffectorOnCollectionSensorChangeRebindTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testEffectorMaintainsPreviousCollectionThroughRebind() throws Exception { final Set<Integer> input1 = ImmutableSet.of(1, 2); final Set<Integer> input2 = ImmutableSet.of(2, 3); final Set<Integer> input3 = ImmutableSet.of(3, 4); Entity testEntity = app().createAndManageChild(EntitySpec.create(TestEntity.class) .policy(PolicySpec.create(InvokeEffectorOnCollectionSensorChange.class) .configure(InvokeEffectorOnCollectionSensorChange.TRIGGER_SENSOR, SENSOR) .configure(InvokeEffectorOnCollectionSensorChange.ON_REMOVED_EFFECTOR_NAME, "on-removed-effector")) .addInitializer(new AddEffector(Effectors.effector(Void.class, "on-removed-effector") .impl(new PublishingEffector()) .build()))); testEntity.sensors().set(SENSOR, input1); testEntity.sensors().set(SENSOR, input2); EntityAsserts.assertAttributeEqualsEventually(testEntity, REMOVED_EFFECTOR_VALUES, ImmutableSet.<Object>of(1)); newApp = rebind(); testEntity = Iterables.getOnlyElement(newApp.getChildren()); testEntity.sensors().set(SENSOR, input3); EntityAsserts.assertAttributeEqualsEventually(testEntity, REMOVED_EFFECTOR_VALUES, ImmutableSet.<Object>of(1, 2)); }
Example #7
Source File: MembershipTrackingPolicyTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testNotifiedOfExtraTrackedSensorsIfDuplicate() throws Exception { TestEntity e1 = createAndManageChildOf(group); app.policies().removeAllPolicies(); RecordingMembershipTrackingPolicy nonDuplicateTrackingPolicy = app.policies().add(PolicySpec.create(RecordingMembershipTrackingPolicy.class) .configure(AbstractMembershipTrackingPolicy.SENSORS_TO_TRACK, ImmutableSet.<Sensor<?>>of(TestEntity.NAME)) .configure(AbstractMembershipTrackingPolicy.NOTIFY_ON_DUPLICATES, true) .configure(AbstractMembershipTrackingPolicy.GROUP, group)); e1.sensors().set(TestEntity.NAME, "myname"); assertRecordsEventually(nonDuplicateTrackingPolicy, Record.newAdded(e1), Record.newChanged(e1)); e1.sensors().set(TestEntity.NAME, "myname"); assertRecordsEventually(nonDuplicateTrackingPolicy, Record.newAdded(e1), Record.newChanged(e1), Record.newChanged(e1)); e1.sensors().set(TestEntity.NAME, "mynewname"); assertRecordsEventually(nonDuplicateTrackingPolicy, Record.newAdded(e1), Record.newChanged(e1), Record.newChanged(e1), Record.newChanged(e1)); }
Example #8
Source File: AbstractGeoDnsServiceImpl.java From brooklyn-library with Apache License 2.0 | 6 votes |
/** * Start the tracker. * <p> * Subclasses should take care to synchronize on {@link #trackerLock}. */ protected void startTracker() { synchronized (trackerLock) { if (targetEntityProvider == null || !getManagementSupport().isDeployed()) { log.debug("Tracker for " + this + " not yet active: " + targetEntityProvider + " / " + getManagementContext()); return; } endTracker(); ImmutableSet.Builder<Sensor<?>> sensorsToTrack = ImmutableSet.<Sensor<?>>builder().add( HOSTNAME, ADDRESS, Attributes.MAIN_URI, WebAppService.ROOT_URL); // Don't subscribe to lifecycle events if entities will be included regardless of their status. if (Boolean.TRUE.equals(config().get(FILTER_FOR_RUNNING))) { sensorsToTrack.add(Attributes.SERVICE_STATE_ACTUAL); } log.debug("Initializing tracker for " + this + ", following " + targetEntityProvider); tracker = policies().add(PolicySpec.create(MemberTrackingPolicy.class) .displayName("GeoDNS targets tracker") .configure(AbstractMembershipTrackingPolicy.SENSORS_TO_TRACK, sensorsToTrack.build()) .configure(AbstractMembershipTrackingPolicy.GROUP, targetEntityProvider)); refreshGroupMembership(); } }
Example #9
Source File: EntityConcurrencyTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testConcurrentAddPolicy() throws Exception { final int NUM_TASKS = 100; int numPrePolicies = entity.policies().size(); List<ListenableFuture<?>> futures = Lists.newArrayList(); for (int i = 0; i < NUM_TASKS; i++) { ListenableFuture<?> future = executor.submit(new Runnable() { @Override public void run() { entity.policies().add(PolicySpec.create(BasicPolicyTest.MyPolicy.class)); }}); futures.add(future); } Futures.allAsList(futures).get(); assertEquals(entity.policies().size(), NUM_TASKS+numPrePolicies); }
Example #10
Source File: CatalogTransformer.java From brooklyn-server with Apache License 2.0 | 6 votes |
/** @deprecated since 0.12.0 use {@link RegisteredType} methods instead */ @Deprecated public static CatalogPolicySummary catalogPolicySummary(BrooklynRestResourceUtils b, CatalogItem<? extends Policy,PolicySpec<?>> item, UriBuilder ub) { final Set<PolicyConfigSummary> config = Sets.newLinkedHashSet(); try{ final PolicySpec<?> spec = (PolicySpec<?>) b.getCatalog().peekSpec(item); AtomicInteger priority = new AtomicInteger(); for (SpecParameter<?> input: spec.getParameters()) { config.add(ConfigTransformer.of(input).uiIncrementAndSetPriorityIfPinned(priority).transformLegacyPolicyConfig()); } }catch (Exception e) { Exceptions.propagateIfFatal(e); log.trace("Unable to create policy spec for "+item+": "+e, e); } return new CatalogPolicySummary(item.getSymbolicName(), item.getVersion(), item.getContainingBundle(), item.getDisplayName(), item.getJavaType(), item.getCatalogItemType().toString(), item.getPlanYaml(), item.getDescription(), tidyIconLink(b, item, item.getIconUrl(), ub), config, item.tags().getTags(), item.isDeprecated(), makeLinks(item, ub)); }
Example #11
Source File: CatalogTransformer.java From brooklyn-server with Apache License 2.0 | 6 votes |
public static CatalogPolicySummary catalogPolicySummary(BrooklynRestResourceUtils b, RegisteredType item, UriBuilder ub) { final Set<PolicyConfigSummary> config = Sets.newLinkedHashSet(); PolicySpec<?> spec = null; try{ spec = b.getTypeRegistry().createSpec(item, null, PolicySpec.class); AtomicInteger priority = new AtomicInteger(); for (SpecParameter<?> input: spec.getParameters()) { config.add(ConfigTransformer.of(input).uiIncrementAndSetPriorityIfPinned(priority).transformLegacyPolicyConfig()); } }catch (Exception e) { Exceptions.propagateIfFatal(e); log.trace("Unable to create policy spec for "+item+": "+e, e); } return new CatalogPolicySummary(item.getSymbolicName(), item.getVersion(), item.getContainingBundle(), item.getDisplayName(), spec!=null ? spec.getType().getName() : item.getSuperTypes().toString(), CatalogItemType.POLICY.toString(), RegisteredTypes.getImplementationDataStringForSpec(item), item.getDescription(), tidyIconLink(b, item, item.getIconUrl(), ub), config, item.getTags(), item.isDeprecated(), makeLinks(item, ub)); }
Example #12
Source File: ScheduledPolicyRebindTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testPeriodicEffectorStartsAfterRebind() throws Exception { TestEntity origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class) .policy(PolicySpec.create(PeriodicEffectorPolicy.class) .configure(PeriodicEffectorPolicy.EFFECTOR, "myEffector") .configure(PeriodicEffectorPolicy.EFFECTOR_ARGUMENTS, ImmutableMap.of()) .configure(PeriodicEffectorPolicy.PERIOD, Duration.millis(1)) .configure(PeriodicEffectorPolicy.TIME, "immediately") .configure(PeriodicEffectorPolicy.START_SENSOR, START))); newApp = rebind(RebindOptions.create().terminateOrigManagementContext(true)); TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); Policy newPolicy = Iterables.find(newEntity.policies(), Predicates.instanceOf(PeriodicEffectorPolicy.class)); Asserts.assertFalse(newPolicy.config().get(PeriodicEffectorPolicy.RUNNING)); Asserts.assertFalse(newEntity.getCallHistory().contains("myEffector")); newEntity.sensors().set(START, Boolean.TRUE); assertConfigEqualsEventually(newPolicy, PeriodicEffectorPolicy.RUNNING, true); assertCallHistoryEventually(newEntity, "myEffector", 2); }
Example #13
Source File: ScheduledPolicyRebindTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testLongPeriodicEffectorFiresAfterRebind() throws Exception { TestEntity origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class) .policy(PolicySpec.create(PeriodicEffectorPolicy.class) .configure(PeriodicEffectorPolicy.EFFECTOR, "myEffector") .configure(PeriodicEffectorPolicy.EFFECTOR_ARGUMENTS, ImmutableMap.of()) .configure(PeriodicEffectorPolicy.PERIOD, Duration.millis(100)) .configure(PeriodicEffectorPolicy.TIME, "immediately") .configure(PeriodicEffectorPolicy.START_SENSOR, START))); origEntity.sensors().set(START, Boolean.TRUE); assertCallHistoryContainsEventually(origEntity, "myEffector"); newApp = rebind(RebindOptions.create().terminateOrigManagementContext(true)); TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); Policy newPolicy = Iterables.find(newEntity.policies(), Predicates.instanceOf(PeriodicEffectorPolicy.class)); assertConfigEqualsEventually(newPolicy, PeriodicEffectorPolicy.RUNNING, true); assertCallHistoryContainsEventually(newEntity, "myEffector"); }
Example #14
Source File: CampInternalUtils.java From brooklyn-server with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private static PolicySpec<? extends Policy> resolvePolicySpec( String versionedId, BrooklynClassLoadingContext loader, Set<String> encounteredCatalogTypes) { PolicySpec<? extends Policy> spec; RegisteredType item = loader.getManagementContext().getTypeRegistry().get( CatalogUpgrades.getTypeUpgradedIfNecessary(loader.getManagementContext(), versionedId)); if (item != null && !encounteredCatalogTypes.contains(item.getSymbolicName())) { RegisteredTypeLoadingContext context = RegisteredTypeLoadingContexts.alreadyEncountered(encounteredCatalogTypes); return loader.getManagementContext().getTypeRegistry().createSpec(item, context, PolicySpec.class); } else { // TODO-type-registry pass the loader in to the above, and allow it to load with the loader spec = PolicySpec.create(loader.loadClass(versionedId, Policy.class)); } return spec; }
Example #15
Source File: ScheduledPolicyRebindTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testShortPeriodicEffectorFiresAfterRebind() throws Exception { TestEntity origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class) .policy(PolicySpec.create(PeriodicEffectorPolicy.class) .configure(PeriodicEffectorPolicy.EFFECTOR, "myEffector") .configure(PeriodicEffectorPolicy.EFFECTOR_ARGUMENTS, ImmutableMap.of()) .configure(PeriodicEffectorPolicy.PERIOD, Duration.millis(1)) .configure(PeriodicEffectorPolicy.TIME, "immediately") .configure(PeriodicEffectorPolicy.START_SENSOR, START))); origEntity.sensors().set(START, Boolean.TRUE); assertCallHistoryContainsEventually(origEntity, "myEffector"); newApp = rebind(RebindOptions.create().terminateOrigManagementContext(true)); TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); Policy newPolicy = Iterables.find(newEntity.policies(), Predicates.instanceOf(PeriodicEffectorPolicy.class)); assertConfigEqualsEventually(newPolicy, PeriodicEffectorPolicy.RUNNING, true); int calls = newEntity.getCallHistory().size(); assertCallHistoryEventually(newEntity, "myEffector", calls + 2); }
Example #16
Source File: RebindPolicyTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testExpungesOnEntityUnmanaged() throws Exception { Location loc = origManagementContext.getLocationRegistry().getLocationManaged("localhost"); TestEntity entity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class)); MyPolicy policy = entity.policies().add(PolicySpec.create(MyPolicy.class)); MyEnricher enricher = entity.enrichers().add(EnricherSpec.create(MyEnricher.class)); RebindTestUtils.waitForPersisted(origApp); Entities.unmanage(entity); Locations.unmanage(loc); RebindTestUtils.stopPersistence(origApp); BrooklynMementoManifest manifest = loadMementoManifest(); assertFalse(manifest.getEntityIdToManifest().containsKey(entity.getId())); assertFalse(manifest.getPolicyIdToType().containsKey(policy.getId())); assertFalse(manifest.getEnricherIdToType().containsKey(enricher.getId())); assertFalse(manifest.getLocationIdToType().containsKey(loc.getId())); }
Example #17
Source File: AutoScalerPolicyTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@BeforeMethod(alwaysRun=true) public void setUp() throws Exception { super.setUp(); log.info("resetting "+getClass().getSimpleName()); cluster = app.createAndManageChild(EntitySpec.create(TestCluster.class).configure(TestCluster.INITIAL_SIZE, 1)); resizable = cluster.addChild(EntitySpec.create(LocallyResizableEntity.class) .configure(LocallyResizableEntity.TEST_CLUSTER, cluster)); PolicySpec<AutoScalerPolicy> policySpec = PolicySpec.create(AutoScalerPolicy.class).configure(AutoScalerPolicy.RESIZE_OPERATOR, new ResizeOperator() { @Override public Integer resize(Entity entity, Integer desiredSize) { log.info("resizing to "+desiredSize); policyResizes.add(desiredSize); return ((Resizable)entity).resize(desiredSize); } }); policy = resizable.policies().add(policySpec); policyResizes.clear(); }
Example #18
Source File: ConnectionFailureDetectorTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test(groups="Integration") // Because slow public void testNotNotifiedOfTemporaryRecoveryDuringStabilisationDelay() throws Exception { final long stabilisationDelay = 1000; app.policies().add(PolicySpec.create(ConnectionFailureDetector.class) .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress) .configure(ConnectionFailureDetector.CONNECTION_RECOVERED_STABILIZATION_DELAY, Duration.of(stabilisationDelay))); stopServerSocket(); assertHasEventEventually(HASensors.CONNECTION_FAILED, Predicates.<Object>equalTo(app), null); events.clear(); startServerSocket(); Thread.sleep(POLL_PERIOD+OVERHEAD); stopServerSocket(); assertNoEventsContinually(Duration.of(stabilisationDelay + OVERHEAD)); }
Example #19
Source File: AdvertiseWinrmLoginPolicyTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testAdvertisesMachineLoginDetails() throws Exception { TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) .policy(PolicySpec.create(AdvertiseWinrmLoginPolicy.class))); WinRmMachineLocation machine = mgmt.getLocationManager().createLocation(LocationSpec.create(WinRmMachineLocation.class) .configure("address", "1.2.3.4") .configure("user", "myuser") .configure("port", 5678) .configure("password", "mypassword")); app.start(ImmutableList.of(machine)); String expected = "myuser : mypassword @ 1.2.3.4:5678"; EntityAsserts.assertAttributeEqualsEventually(entity, AdvertiseWinrmLoginPolicy.VM_USER_CREDENTIALS, expected); }
Example #20
Source File: ConfigKeyConstraintTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testExceptionWhenPolicyHasInvalidConfig() { try { mgmt.getEntityManager().createPolicy(PolicySpec.create(PolicyWithConfigConstraint.class) .configure(PolicyWithConfigConstraint.NON_NULL_CONFIG, (Object) null)); Asserts.shouldHaveFailedPreviously("Expected exception when creating policy with missing config"); } catch (Exception e) { Asserts.expectedFailureOfType(e, ConstraintViolationException.class); } }
Example #21
Source File: ConnectionFailureDetectorTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testNotifiedOfFailure() throws Exception { app.policies().add(PolicySpec.create(ConnectionFailureDetector.class) .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress)); stopServerSocket(); assertHasEventEventually(HASensors.CONNECTION_FAILED, Predicates.<Object>equalTo(app), null); assertEquals(events.size(), 1, "events="+events); }
Example #22
Source File: ConnectionFailureDetectorTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test(groups="Integration") // Has a 1 second wait public void testNotNotifiedOfFailuresForHealthy() throws Exception { // Create members before and after the policy is registered, to test both scenarios app.policies().add(PolicySpec.create(ConnectionFailureDetector.class) .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress)); assertNoEventsContinually(); }
Example #23
Source File: MembershipTrackingPolicyTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); loc = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)); entityManager = app.getManagementContext().getEntityManager(); group = app.createAndManageChild(EntitySpec.create(BasicGroup.class) .configure("childrenAsMembers", true)); policy = app.policies().add(PolicySpec.create(RecordingMembershipTrackingPolicy.class) .configure("group", group)); app.start(ImmutableList.of(loc)); }
Example #24
Source File: ServiceReplacerTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test(groups="Integration") // 1s wait public void testStopFailureOfOldEntityDoesNotSetClusterOnFire() throws Exception { app.subscriptions().subscribe(null, ServiceReplacer.ENTITY_REPLACEMENT_FAILED, eventListener); final DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(FailingEntity.class) .configure(FailingEntity.FAIL_ON_STOP_CONDITION, predicateOnlyTrueForCallAt(1))) .configure(DynamicCluster.INITIAL_SIZE, 2)); app.start(ImmutableList.<Location>of(loc)); cluster.policies().add(PolicySpec.create(ServiceReplacer.class) .configure(ServiceReplacer.FAILURE_SENSOR_TO_MONITOR, HASensors.ENTITY_FAILED)); final Set<Entity> initialMembers = ImmutableSet.copyOf(cluster.getMembers()); final TestEntity e1 = (TestEntity) Iterables.get(initialMembers, 0); e1.sensors().emit(HASensors.ENTITY_FAILED, new FailureDescriptor(e1, "simulate failure")); // Expect e1 to be replaced Asserts.succeedsEventually(new Runnable() { @Override public void run() { Set<Entity> newMembers = Sets.difference(ImmutableSet.copyOf(cluster.getMembers()), initialMembers); Set<Entity> removedMembers = Sets.difference(initialMembers, ImmutableSet.copyOf(cluster.getMembers())); assertEquals(removedMembers, ImmutableSet.of(e1)); assertEquals(newMembers.size(), 1); assertEquals(((TestEntity)Iterables.getOnlyElement(newMembers)).getCallHistory(), ImmutableList.of("start")); assertEquals(e1.getCallHistory(), ImmutableList.of("start", "stop")); assertFalse(Entities.isManaged(e1)); }}); // Failure to stop the failed member should not cause "on-fire" of cluster Asserts.succeedsContinually(new Runnable() { @Override public void run() { assertNotEquals(cluster.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.ON_FIRE); }}); }
Example #25
Source File: ServiceReplacerTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test(groups={"Integration", "Broken"}) // has a 1 second wait public void testDoesNotOnFireWhenFailToReplaceMember() throws Exception { app.subscriptions().subscribe(null, ServiceReplacer.ENTITY_REPLACEMENT_FAILED, eventListener); final DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(FailingEntity.class) .configure(FailingEntity.FAIL_ON_START_CONDITION, predicateOnlyTrueForCallAtOrAfter(2))) .configure(DynamicCluster.INITIAL_SIZE, 1) .configure(DynamicCluster.QUARANTINE_FAILED_ENTITIES, true)); app.start(ImmutableList.<Location>of(loc)); cluster.policies().add(PolicySpec.create(ServiceReplacer.class) .configure(ServiceReplacer.FAILURE_SENSOR_TO_MONITOR, HASensors.ENTITY_FAILED) .configure(ServiceReplacer.SET_ON_FIRE_ON_FAILURE, false)); final Set<Entity> initialMembers = ImmutableSet.copyOf(cluster.getMembers()); final TestEntity e1 = (TestEntity) Iterables.get(initialMembers, 0); e1.sensors().emit(HASensors.ENTITY_FAILED, new FailureDescriptor(e1, "simulate failure")); // Configured to not mark cluster as on fire Asserts.succeedsContinually(new Runnable() { @Override public void run() { assertNotEquals(cluster.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.ON_FIRE, "Unexpected ON_FIRE state"); }}); // And will have received notification event about it assertEventuallyHasEntityReplacementFailedEvent(cluster); }
Example #26
Source File: ServiceReplacerTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testReplacesFailedMember() throws Exception { final DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class)) .configure(DynamicCluster.INITIAL_SIZE, 3)); app.start(ImmutableList.<Location>of(loc)); cluster.policies().add(PolicySpec.create(ServiceReplacer.class) .configure(ServiceReplacer.FAILURE_SENSOR_TO_MONITOR, HASensors.ENTITY_FAILED)); final Set<Entity> initialMembers = ImmutableSet.copyOf(cluster.getMembers()); final TestEntity e1 = (TestEntity) Iterables.get(initialMembers, 1); e1.sensors().emit(HASensors.ENTITY_FAILED, new FailureDescriptor(e1, "simulate failure")); // Expect e1 to be replaced Asserts.succeedsEventually(new Runnable() { @Override public void run() { Set<Entity> newMembers = Sets.difference(ImmutableSet.copyOf(cluster.getMembers()), initialMembers); Set<Entity> removedMembers = Sets.difference(initialMembers, ImmutableSet.copyOf(cluster.getMembers())); assertEquals(removedMembers, ImmutableSet.of(e1)); assertEquals(newMembers.size(), 1); assertEquals(((TestEntity)Iterables.getOnlyElement(newMembers)).getCallHistory(), ImmutableList.of("start")); assertEquals(e1.getCallHistory(), ImmutableList.of("start", "stop")); assertFalse(Entities.isManaged(e1)); }}); }
Example #27
Source File: ServiceRestarterTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testRestartDoesNotBlockOtherSubscriptions() throws Exception { final CountDownLatch inRestartLatch = new CountDownLatch(1); final CountDownLatch continueRestartLatch = new CountDownLatch(1); final FailingEntity e2 = app.createAndManageChild(EntitySpec.create(FailingEntity.class) .configure(FailingEntity.FAIL_ON_RESTART, true) .configure(FailingEntity.EXEC_ON_FAILURE, new Function<Object, Void>() { @Override public Void apply(Object input) { inRestartLatch.countDown(); try { continueRestartLatch.await(); } catch (InterruptedException e) { throw Exceptions.propagate(e); } return null; }})); e2.policies().add(PolicySpec.create(ServiceRestarter.class) .configure(ServiceRestarter.FAILURE_SENSOR_TO_MONITOR, HASensors.ENTITY_FAILED)); e2.subscriptions().subscribe(e2, TestEntity.SEQUENCE, eventListener); // Cause failure, and wait for entity.restart to be blocking e2.sensors().emit(HASensors.ENTITY_FAILED, new FailureDescriptor(e1, "simulate failure")); assertTrue(inRestartLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)); // Expect other notifications to continue to get through e2.sensors().set(TestEntity.SEQUENCE, 1); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(Iterables.getOnlyElement(events).getValue(), 1); }}); // Allow restart to finish continueRestartLatch.countDown(); }
Example #28
Source File: BasicPolicyTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testTagsFromSpec() throws Exception { MyPolicy policy = app.policies().add(PolicySpec.create(MyPolicy.class).tag(99).uniqueTag("x")); assertEquals(policy.tags().getTags(), MutableSet.of("x", 99)); assertEquals(policy.getUniqueTag(), "x"); }
Example #29
Source File: PolicySubscriptionTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); loc = app.newSimulatedLocation(); entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); otherEntity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); listener = new RecordingSensorEventListener<>(); policy = entity.policies().add(PolicySpec.create(MyPolicy.class)); app.start(ImmutableList.of(loc)); }
Example #30
Source File: SeaCloudsManagementPolicyLiveTest.java From SeaCloudsPlatform with Apache License 2.0 | 5 votes |
protected PolicySpec<SeaCloudsManagementPolicy> getPolicySpec() { return PolicySpec.create(SeaCloudsManagementPolicy.class) .configure(SeaCloudsManagementPolicy.SLA_ENDPOINT, SLA_ENDPOINT) .configure(SeaCloudsManagementPolicy.SLA_AGREEMENT, getBase64Agreement()) .configure(SeaCloudsManagementPolicy.T4C_ENDPOINT, T4C_ENDPOINT) .configure(SeaCloudsManagementPolicy.T4C_RULES, getBase64Rules()) .configure(SeaCloudsManagementPolicy.INFLUXDB_ENDPOINT, INFLUXDB_ENDPOINT) .configure(SeaCloudsManagementPolicy.INFLUXDB_DATABASE, INFLUXDB_DATABASE) .configure(SeaCloudsManagementPolicy.INFLUXDB_USERNAME, INFLUXDB_USERNAME) .configure(SeaCloudsManagementPolicy.INFLUXDB_PASSWORD, INFLUXDB_PASSWORD) .configure(SeaCloudsManagementPolicy.GRAFANA_ENDPOINT, GRAFANA_ENDPOINT) .configure(SeaCloudsManagementPolicy.GRAFANA_USERNAME, GRAFANA_USERNAME) .configure(SeaCloudsManagementPolicy.GRAFANA_PASSWORD, GRAFANA_PASSWORD); }