Java Code Examples for org.apache.brooklyn.core.sensor.Sensors#newStringSensor()

The following examples show how to use org.apache.brooklyn.core.sensor.Sensors#newStringSensor() . 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: SensorPropagatingEnricherTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnricherSpecPropagatesSpecificSensorAndMapsOthers() throws Exception {
    final AttributeSensor<String> ANOTHER_ATTRIBUTE = Sensors.newStringSensor("another.attribute", "");
    
    app.enrichers().add(EnricherSpec.create(Propagator.class)
            .configure(MutableMap.builder()
                    .putIfNotNull(Propagator.PRODUCER, entity)
                    .putIfNotNull(Propagator.SENSOR_MAPPING, ImmutableMap.of(TestEntity.NAME, ANOTHER_ATTRIBUTE))
                    .putIfNotNull(Propagator.PROPAGATING, ImmutableList.of(TestEntity.SEQUENCE))
                    .build()));

    // name propagated as alternative sensor
    entity.sensors().set(TestEntity.NAME, "foo");
    EntityAsserts.assertAttributeEqualsEventually(app, ANOTHER_ATTRIBUTE, "foo");
    
    // sequence also propagated
    entity.sensors().set(TestEntity.SEQUENCE, 2);
    EntityAsserts.assertAttributeEqualsEventually(app, TestEntity.SEQUENCE, 2);

    // name not propagated as original sensor
    EntityAsserts.assertAttributeEqualsContinually(MutableMap.of("timeout", 100), app, TestEntity.NAME, null);
}
 
Example 2
Source File: TestSensorAndEffectorInitializer.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(@SuppressWarnings("deprecation") org.apache.brooklyn.api.entity.EntityLocal entity) {
    Effector<String> eff = Effectors.effector(String.class, EFFECTOR_SAY_HELLO).parameter(String.class, "name").impl(
        new EffectorBody<String>() {
            @Override
            public String call(ConfigBag parameters) {
                Object name = parameters.getStringKey("name");
                entity().sensors().set(Sensors.newStringSensor(SENSOR_LAST_HELLO), Strings.toString(name));
                return helloWord()+" "+name;
            }
        }).build();
    ((EntityInternal)entity).getMutableEntityType().addEffector(eff);
    
    ((EntityInternal)entity).getMutableEntityType().addSensor(Sensors.newStringSensor(SENSOR_HELLO_DEFINED));
    
    AttributeSensor<String> emitted = Sensors.newStringSensor(SENSOR_HELLO_DEFINED_EMITTED);
    ((EntityInternal)entity).getMutableEntityType().addSensor(emitted);
    entity.sensors().set(emitted, "1");
}
 
Example 3
Source File: DslAndRebindYamlTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegexReplacementFunctionWithAttributeWhenReady() throws Exception {
    Entity testEntity = setupAndCheckTestEntityInBasicYamlWith(
            "  brooklyn.enrichers:",
            "  - type: org.apache.brooklyn.enricher.stock.Transformer",
            "    brooklyn.config:",
            "      enricher.sourceSensor: $brooklyn:sensor(\"test.name\")",
            "      enricher.targetSensor: $brooklyn:sensor(\"test.name.transformed\")",
            "      enricher.transformation: $brooklyn:function.regexReplacement($brooklyn:attributeWhenReady(\"test.pattern\"), $brooklyn:attributeWhenReady(\"test.replacement\"))"
    );
    testEntity.sensors().set(Sensors.newStringSensor("test.pattern"), "foo");
    testEntity.sensors().set(Sensors.newStringSensor("test.replacement"), "bar");
    testEntity.sensors().set(TestEntity.NAME, "somefooname");
    AttributeSensor<String> transformedSensor = Sensors.newStringSensor("test.name.transformed");
    EntityAsserts.assertAttributeEqualsEventually(testEntity, transformedSensor, "somebarname");
}
 
Example 4
Source File: OnPublicNetworkEnricherTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public <T> void testIgnoresNonMatchingSensors() throws Exception {
    AttributeSensor<URI> sensor1 = Sensors.newSensor(URI.class, "my.different");
    AttributeSensor<URL> sensor2 = Sensors.newSensor(URL.class, "my.different2");
    AttributeSensor<String> sensor3 = Sensors.newStringSensor("my.different3");
    AttributeSensor<Integer> sensor4 = Sensors.newIntegerSensor("my.different4");
    AttributeSensor<HostAndPort> sensor5 = Sensors.newSensor(HostAndPort.class, "my.different5");

    entity.sensors().set(Attributes.SUBNET_ADDRESS, "127.0.0.1");
    entity.sensors().set(sensor1, URI.create("http://127.0.0.1:1234/my/path"));
    entity.sensors().set(sensor2, new URL("http://127.0.0.1:1234/my/path"));
    entity.sensors().set(sensor3, "http://127.0.0.1:1234/my/path");
    entity.sensors().set(sensor4, 1234);
    entity.sensors().set(sensor5, HostAndPort.fromParts("127.0.0.1", 1234));
    portForwardManager.associate("myPublicIp", HostAndPort.fromParts("mypublichost", 5678), machine, 1234);
    entity.addLocations(ImmutableList.of(machine));
    
    entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class));

    Map<AttributeSensor<?>, Object> allSensors = entity.sensors().getAll();
    String errMsg = "sensors="+allSensors;
    for (AttributeSensor<?> sensor : allSensors.keySet()) {
        String name = sensor.getName();
        assertFalse(name.startsWith("my.different") && sensor.getName().contains("public"), errMsg);
    }
}
 
Example 5
Source File: SensorSummaryTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testSensorWithMultipleOpenUrlActionsRegistered() throws IOException {
    AttributeSensor<String> sensor = Sensors.newStringSensor("sensor1");
    entity.sensors().set(sensor, "http://myval");
    RendererHints.register(sensor, RendererHints.namedActionWithUrl());
    RendererHints.register(sensor, RendererHints.namedActionWithUrl());

    SensorSummary summary = SensorTransformer.sensorSummary(entity, sensor, UriBuilder.fromPath("/"));

    assertEquals(summary.getLinks().get("action:open"), URI.create("http://myval"));
}
 
Example 6
Source File: OnSubnetNetworkEnricherTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public <T> void testTransformsAllMatchingSensors() throws Exception {
    AttributeSensor<URI> stronglyTypedUri = Sensors.newSensor(URI.class, "strongly.typed.uri");
    AttributeSensor<String> stringUri = Sensors.newStringSensor("string.uri");
    AttributeSensor<URL> stronglyTypedUrl = Sensors.newSensor(URL.class, "strongly.typed.url");
    AttributeSensor<String> stringUrl = Sensors.newStringSensor("string.url");
    AttributeSensor<Integer> intPort = Sensors.newIntegerSensor("int.port");
    AttributeSensor<String> stringPort = Sensors.newStringSensor("string.port");
    AttributeSensor<HostAndPort> hostAndPort = Sensors.newSensor(HostAndPort.class, "hostAndPort.endpoint");
    AttributeSensor<String> stringHostAndPort = Sensors.newStringSensor("stringHostAndPort.endpoint");

    entity.sensors().set(Attributes.SUBNET_ADDRESS, privateIp);
    entity.sensors().set(stronglyTypedUri, URI.create("http://"+publicIp+":1234/my/path"));
    entity.sensors().set(stringUri, "http://"+publicIp+":1234/my/path");
    entity.sensors().set(stronglyTypedUrl, new URL("http://"+publicIp+":1234/my/path"));
    entity.sensors().set(stringUrl, "http://"+publicIp+":1234/my/path");
    entity.sensors().set(intPort, 1234);
    entity.sensors().set(stringPort, "1234");
    entity.sensors().set(hostAndPort, HostAndPort.fromParts(""+publicIp+"", 1234));
    entity.sensors().set(stringHostAndPort, ""+publicIp+":1234");
    entity.addLocations(ImmutableList.of(machine));
    
    entity.enrichers().add(EnricherSpec.create(OnSubnetNetworkEnricher.class));

    assertAttributeEqualsEventually("strongly.typed.uri.mapped.subnet", "http://"+privateIp+":1234/my/path");
    assertAttributeEqualsEventually("string.uri.mapped.subnet", "http://"+privateIp+":1234/my/path");
    assertAttributeEqualsEventually("strongly.typed.url.mapped.subnet", "http://"+privateIp+":1234/my/path");
    assertAttributeEqualsEventually("string.url.mapped.subnet", "http://"+privateIp+":1234/my/path");
    assertAttributeEqualsEventually("int.endpoint.mapped.subnet", ""+privateIp+":1234");
    assertAttributeEqualsEventually("string.endpoint.mapped.subnet", ""+privateIp+":1234");
    assertAttributeEqualsEventually("hostAndPort.endpoint.mapped.subnet", ""+privateIp+":1234");
    assertAttributeEqualsEventually("stringHostAndPort.endpoint.mapped.subnet", ""+privateIp+":1234");
}
 
Example 7
Source File: OnSubnetNetworkEnricherTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public <T> void testIgnoresNonMatchingSensors() throws Exception {
    AttributeSensor<URI> sensor1 = Sensors.newSensor(URI.class, "my.different");
    AttributeSensor<URL> sensor2 = Sensors.newSensor(URL.class, "my.different2");
    AttributeSensor<String> sensor3 = Sensors.newStringSensor("my.different3");
    AttributeSensor<Integer> sensor4 = Sensors.newIntegerSensor("my.different4");
    AttributeSensor<HostAndPort> sensor5 = Sensors.newSensor(HostAndPort.class, "my.different5");

    entity.sensors().set(Attributes.SUBNET_ADDRESS, privateIp);
    entity.sensors().set(sensor1, URI.create("http://"+publicIp+":1234/my/path"));
    entity.sensors().set(sensor2, new URL("http://"+publicIp+":1234/my/path"));
    entity.sensors().set(sensor3, "http://"+publicIp+":1234/my/path");
    entity.sensors().set(sensor4, 1234);
    entity.sensors().set(sensor5, HostAndPort.fromParts(publicIp, 1234));
    entity.addLocations(ImmutableList.of(machine));
    
    entity.enrichers().add(EnricherSpec.create(OnSubnetNetworkEnricher.class));

    Asserts.succeedsContinually(ImmutableMap.of("timeout", VERY_SHORT_WAIT), new Runnable() {
        @Override public void run() {
            Map<AttributeSensor<?>, Object> allSensors = entity.sensors().getAll();
            String errMsg = "sensors="+allSensors;
            for (AttributeSensor<?> sensor : allSensors.keySet()) {
                String name = sensor.getName();
                assertFalse(name.startsWith("my.different") && sensor.getName().contains("subnet"), errMsg);
            }
        }});
}
 
Example 8
Source File: InvokeEffectorOnSensorChangeIntegrationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups = "Integration")
public void testIsBusySensorAlwaysFalseAtEnd() throws InterruptedException {
    /*
     * Stress-test isBusy. Reliably failed with insufficient synchronisation
     * in AbstractInvokeEffectorPolicy.
     */
    final AttributeSensor<String> sensor = Sensors.newStringSensor("my-sensor");
    final AttributeSensor<Boolean> isBusy = Sensors.newBooleanSensor("is-busy");
    Effector<Void> effector = Effectors.effector(Void.class, "effector")
            .impl(new DoNothingEffector())
            .build();
    final BasicEntity entity = app.createAndManageChild(EntitySpec.create(BasicEntity.class)
            .addInitializer(new AddEffector(effector))
            .policy(PolicySpec.create(InvokeEffectorOnSensorChange.class)
                    .configure(InvokeEffectorOnSensorChange.SENSOR, sensor)
                    .configure(InvokeEffectorOnSensorChange.EFFECTOR, "effector")
                    .configure(InvokeEffectorOnSensorChange.IS_BUSY_SENSOR_NAME, isBusy.getName())));
    final AtomicInteger threadId = new AtomicInteger();
    Thread[] threads = new Thread[10];
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new Thread(new Runnable() {
            private int count = 0;
            @Override
            public void run() {
                int id = threadId.incrementAndGet();
                while (count++ < 1000) {
                    entity.sensors().set(sensor, "thread-" + id + "-" + count);
                }
            }
        });
        threads[i].start();
    }
    for (Thread thread : threads) {
        thread.join();
    }

    EntityAsserts.assertAttributeEqualsEventually(entity, isBusy, false);
}
 
Example 9
Source File: ApplicationLifecycleStateTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/**
 * Tests concurrent modifications to a sensor, asserting that the last notification the subscribers 
 * receives equals the last value that sensor has.
 * 
 * Prior to this being fixed (see https://github.com/apache/brooklyn-server/pull/622), it caused 
 * problems in ComputeServiceIndicatorsFromChildrenAndMembers: it saw a child transition 
 * from "running" to "starting", and thus emitted the on-fire event for the parent entity. As asserted
 * by this test, the enricher should now always receive the events in the correct order (e.g. "starting",
 * "running").
 */
@Test
public void testSettingSensorFromThreads() {
    final TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
    final AttributeSensor<String> TEST_SENSOR = Sensors.newStringSensor("test.sensor");

    final AtomicReference<String> lastSeenState = new AtomicReference<>();
    app.subscriptions().subscribe(app, TEST_SENSOR, new SensorEventListener<String>() {
        @Override
        public void onEvent(SensorEvent<String> event) {
            lastSeenState.set(event.getValue());
            log.debug("seen event=" + event);
        }
    });

    Task<?> first = mgmt.getExecutionManager().submit("setting test sensor", () -> {
            app.sensors().set(TEST_SENSOR, "first");
            log.debug("set first");
        });
    Task<?> second = mgmt.getExecutionManager().submit("setting test sensor", () -> {
            app.sensors().set(TEST_SENSOR, "second");
            log.debug("set second");
        });
    first.blockUntilEnded();
    second.blockUntilEnded();

    Asserts.succeedsEventually(new Runnable() {
        @Override
        public void run() {
            EntityAsserts.assertAttributeEquals(app, TEST_SENSOR, lastSeenState.get());
        }
    });
}
 
Example 10
Source File: AttributeMapTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testCanStoreChildThenParentSensor() throws Exception {
    AttributeSensor<String> sensor = Sensors.newStringSensor("a", "");
    AttributeSensor<String> childSensor = Sensors.newStringSensor("a.b", "");
    
    map.update(childSensor, "childValue");
    map.update(sensor, "parentValue");
    
    assertEquals(map.getValue(childSensor), "childValue");
    assertEquals(map.getValue(sensor), "parentValue");
}
 
Example 11
Source File: TestEndpointReachableTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testSensorUriStringReachable() throws Exception {
    String sensorVal = "http://"+serverSocketHostAndPort.getHostText()+":"+serverSocketHostAndPort.getPort();
    AttributeSensor<String> sensor = Sensors.newStringSensor("test.reachable.endpoint");
    app.createAndManageChild(EntitySpec.create(TestEndpointReachable.class)
            .configure(TestEndpointReachable.TARGET_ENTITY, app)
            .configure(TestEndpointReachable.ENDPOINT_SENSOR, sensor));
    app.sensors().set(sensor, sensorVal);
    app.start(ImmutableList.of(loc));
}
 
Example 12
Source File: AttributeMapTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testStoredByPathCanBeRetrieved() throws Exception {
    AttributeSensor<String> sensor1 = Sensors.newStringSensor("a", "");
    AttributeSensor<String> sensor2 = Sensors.newStringSensor("b.c", "");

    map.update(ImmutableList.of("a"), "1val");
    map.update(ImmutableList.of("b", "c"), "2val");
    
    assertEquals(map.getValue(sensor1), "1val");
    assertEquals(map.getValue(sensor2), "2val");
    
    assertEquals(map.getValue(ImmutableList.of("a")), "1val");
    assertEquals(map.getValue(ImmutableList.of("b","c")), "2val");
}
 
Example 13
Source File: OnPublicNetworkEnricherTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public <T> void testCoercesSensorName() throws Exception {
    AttributeSensor<String> sensor = Sensors.newStringSensor("mysensor");

    entity.sensors().set(sensor, "127.0.0.1:1234");
    portForwardManager.associate("myPublicIp", HostAndPort.fromParts("mypublichost", 5678), machine, 1234);
    entity.addLocations(ImmutableList.of(machine));
    
    entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class)
            .configure(OnPublicNetworkEnricher.SENSORS.getName(), ImmutableList.of("mysensor")));

    assertAttributeEqualsEventually("mysensor.mapped.public", "mypublichost:5678");
}
 
Example 14
Source File: OnSubnetNetworkEnricherTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Broken")
public <T> void testTransformsWithDefaultPorts() throws Exception {
    AttributeSensor<String> stringUriWithHttpNoPort = Sensors.newStringSensor("string.uriWithHttpNoPort");
    AttributeSensor<String> stringUriWithHttpsNoPort = Sensors.newStringSensor("string.uriWithHttpsNoPort");

    entity.sensors().set(Attributes.SUBNET_ADDRESS, privateIp);
    entity.sensors().set(stringUriWithHttpNoPort, "http://"+publicIp+"/my/path");
    entity.sensors().set(stringUriWithHttpsNoPort, "https://"+publicIp+"/my/path");
    entity.addLocations(ImmutableList.of(machine));
    
    entity.enrichers().add(EnricherSpec.create(OnSubnetNetworkEnricher.class));

    assertAttributeEqualsEventually("string.uriWithHttpNoPort.mapped.subnet", "http://"+privateIp+"/my/path");
    assertAttributeEqualsEventually("string.uriWithHttpsNoPort.mapped.subnet", "https://"+privateIp+"/my/path");
}
 
Example 15
Source File: RebindEntityTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestoresEntitySensors() throws Exception {
    AttributeSensor<String> myCustomAttribute = Sensors.newStringSensor("my.custom.attribute");
    
    MyEntity origE = origApp.createAndManageChild(EntitySpec.create(MyEntity.class));
    origE.sensors().set(myCustomAttribute, "myval");
    
    newApp = rebind();
    MyEntity newE = (MyEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntity.class));
    assertEquals(newE.getAttribute(myCustomAttribute), "myval");
}
 
Example 16
Source File: WindowsPerformanceCounterFeedTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendPerfCountersToSensors() {
    AttributeSensor<String> stringSensor = Sensors.newStringSensor("foo.bar");
    AttributeSensor<Integer> integerSensor = Sensors.newIntegerSensor("bar.baz");
    AttributeSensor<Double> doubleSensor = Sensors.newDoubleSensor("baz.quux");

    Collection<WindowsPerformanceCounterPollConfig<?>> polls = ImmutableSet.<WindowsPerformanceCounterPollConfig<?>>of(
            new WindowsPerformanceCounterPollConfig<>(stringSensor).performanceCounterName("\\processor information(_total)\\% processor time"),
            new WindowsPerformanceCounterPollConfig<>(integerSensor).performanceCounterName("\\integer.sensor"),
            new WindowsPerformanceCounterPollConfig<>(doubleSensor).performanceCounterName("\\double\\sensor\\with\\multiple\\sub\\paths")
    );

    WindowsPerformanceCounterFeed.SendPerfCountersToSensors sendPerfCountersToSensors = new WindowsPerformanceCounterFeed.SendPerfCountersToSensors(entity, polls);

    assertNull(entity.getAttribute(stringSensor));

    StringBuilder responseBuilder = new StringBuilder();
    // NOTE: This builds the response in a different order to which they are passed to the SendPerfCountersToSensors constructor
    // this tests that the values are applied correctly even if the (possibly non-deterministic) order in which
    // they are returned by the Get-Counter scriptlet is different
    addMockResponse(responseBuilder, "\\\\machine.name\\double\\sensor\\with\\multiple\\sub\\paths", "3.1415926");
    addMockResponse(responseBuilder, "\\\\win-lge7uj2blau\\processor information(_total)\\% processor time", "99.9");
    addMockResponse(responseBuilder, "\\\\machine.name\\integer.sensor", "15");

    sendPerfCountersToSensors.onSuccess(new WinRmToolResponse(responseBuilder.toString(), "", 0));

    EntityAsserts.assertAttributeEquals(entity, stringSensor, "99.9");
    EntityAsserts.assertAttributeEquals(entity, integerSensor, 15);
    EntityAsserts.assertAttributeEquals(entity, doubleSensor, 3.1415926);
}
 
Example 17
Source File: SshCommandSensorYamlTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration")
public void testSupressingDuplicates() throws Exception {
    AttributeSensor<String> mySensor = Sensors.newStringSensor("mySensor");
    
    RecordingSensorEventListener<String> listener = new RecordingSensorEventListener<>();
    Application tmpApp = mgmt().getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
    tmpApp.subscriptions().subscribe(null, mySensor, listener);
    
    RecordingSshTool.setCustomResponse(".*myCommand.*", new RecordingSshTool.CustomResponse(0, "myResponse", null));
    
    Entity app = createAndStartApplication(
        "location:",
        "  localhost:",
        "    sshToolClass: "+RecordingSshTool.class.getName(),
        "services:",
        "- type: " + VanillaSoftwareProcess.class.getName(),
        "  brooklyn.config:",
        "    onbox.base.dir.skipResolution: true",
        "  brooklyn.initializers:",
        "  - type: org.apache.brooklyn.core.sensor.ssh.SshCommandSensor",
        "    brooklyn.config:",
        "      name: mySensor",
        "      command: myCommand",
        "      suppressDuplicates: true",
        "      period: 10ms",
        "      onlyIfServiceUp: false");
    waitForApplicationTasks(app);

    VanillaSoftwareProcess entity = (VanillaSoftwareProcess) Iterables.getOnlyElement(app.getChildren());
    EntityAsserts.assertAttributeEqualsEventually(entity, mySensor, "myResponse");
    listener.assertHasEventEventually(Predicates.alwaysTrue());
    
    Asserts.succeedsContinually(new Runnable() {
        @Override public void run() {
            listener.assertEventCount(1);
        }});
}
 
Example 18
Source File: DslAndRebindYamlTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegexReplacementFunctionWithStrings() throws Exception {
    Entity testEntity = setupAndCheckTestEntityInBasicYamlWith(
            "  brooklyn.enrichers:",
            "  - type: org.apache.brooklyn.enricher.stock.Transformer",
            "    brooklyn.config:",
            "      enricher.sourceSensor: $brooklyn:sensor(\"test.name\")",
            "      enricher.targetSensor: $brooklyn:sensor(\"test.name.transformed\")",
            "      enricher.transformation: $brooklyn:function.regexReplacement(\"foo\", \"bar\")"
    );
    testEntity.sensors().set(TestEntity.NAME, "somefooname");
    AttributeSensor<String> transformedSensor = Sensors.newStringSensor("test.name.transformed");
    EntityAsserts.assertAttributeEqualsEventually(testEntity, transformedSensor, "somebarname");
}
 
Example 19
Source File: OnPublicNetworkEnricherTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public <T> void testTransformsToAddressInSensor() throws Exception {
    AttributeSensor<String> stringUri = Sensors.newStringSensor("string.uri");

    entity.sensors().set(Attributes.ADDRESS, "1.1.1.1");
    entity.sensors().set(stringUri, "http://127.0.0.1:1234/my/path");
    entity.addLocations(ImmutableList.of(machine));

    entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class)
            .configure(OnPublicNetworkEnricher.ADDRESS_SENSOR, Attributes.ADDRESS));

    assertAttributeEqualsEventually("string.uri.mapped.public", "http://1.1.1.1:1234/my/path");
}
 
Example 20
Source File: OnPublicNetworkEnricherTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Test
public <T> void testTransformsAllMatchingSensors() throws Exception {
    AttributeSensor<URI> stronglyTypedUri = Sensors.newSensor(URI.class, "strongly.typed.uri");
    AttributeSensor<String> stringUri = Sensors.newStringSensor("string.uri");
    AttributeSensor<URL> stronglyTypedUrl = Sensors.newSensor(URL.class, "strongly.typed.url");
    AttributeSensor<String> stringUrl = Sensors.newStringSensor("string.url");
    AttributeSensor<Integer> intPort = Sensors.newIntegerSensor("int.port");
    AttributeSensor<String> stringPort = Sensors.newStringSensor("string.port");
    AttributeSensor<Integer> portNoPrefix = Sensors.newIntegerSensor("port");
    AttributeSensor<HostAndPort> endpoint = Sensors.newSensor(HostAndPort.class, "hostAndPort.endpoint");
    AttributeSensor<String> stringEndpoint = Sensors.newStringSensor("string.hostAndPort.endpoint");
    AttributeSensor<HostAndPort> hostAndPort = Sensors.newSensor(HostAndPort.class, "example.hostAndPort");
    AttributeSensor<String> stringHostAndPort = Sensors.newStringSensor("string.hostAndPort");

    entity.sensors().set(Attributes.SUBNET_ADDRESS, "127.0.0.1");
    entity.sensors().set(stronglyTypedUri, URI.create("http://127.0.0.1:1234/my/path"));
    entity.sensors().set(stringUri, "http://127.0.0.1:1234/my/path");
    entity.sensors().set(stronglyTypedUrl, new URL("http://127.0.0.1:1234/my/path"));
    entity.sensors().set(stringUrl, "http://127.0.0.1:1234/my/path");
    entity.sensors().set(intPort, 1234);
    entity.sensors().set(stringPort, "1234");
    entity.sensors().set(portNoPrefix, 1234);
    entity.sensors().set(endpoint, HostAndPort.fromParts("127.0.0.1", 1234));
    entity.sensors().set(stringEndpoint, "127.0.0.1:1234");
    entity.sensors().set(hostAndPort, HostAndPort.fromParts("127.0.0.1", 1234));
    entity.sensors().set(stringHostAndPort, "127.0.0.1:1234");
    portForwardManager.associate("myPublicIp", HostAndPort.fromParts("mypublichost", 5678), machine, 1234);
    entity.addLocations(ImmutableList.of(machine));

    entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class));

    assertAttributeEqualsEventually("strongly.typed.uri.mapped.public", "http://mypublichost:5678/my/path");
    assertAttributeEqualsEventually("string.uri.mapped.public", "http://mypublichost:5678/my/path");
    assertAttributeEqualsEventually("strongly.typed.url.mapped.public", "http://mypublichost:5678/my/path");
    assertAttributeEqualsEventually("string.url.mapped.public", "http://mypublichost:5678/my/path");
    assertAttributeEqualsEventually("int.endpoint.mapped.public", "mypublichost:5678");
    assertAttributeEqualsEventually("string.endpoint.mapped.public", "mypublichost:5678");
    assertAttributeEqualsEventually("endpoint.mapped.public", "mypublichost:5678");
    assertAttributeEqualsEventually("hostAndPort.endpoint.mapped.public", "mypublichost:5678");
    assertAttributeEqualsEventually("string.hostAndPort.endpoint.mapped.public", "mypublichost:5678");
    assertAttributeEqualsEventually("example.hostAndPort.mapped.public", "mypublichost:5678");
    assertAttributeEqualsEventually("string.hostAndPort.mapped.public", "mypublichost:5678");
}