Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.api.mgmt.Task;
import org.apache.brooklyn.camp.brooklyn.BrooklynCampPlatform;
import org.apache.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherNoServer;
import org.apache.brooklyn.camp.brooklyn.spi.creation.CampTypePlanTransformer;
import org.apache.brooklyn.camp.spi.Assembly;
import org.apache.brooklyn.camp.spi.AssemblyTemplate;
import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.StartableApplication;
Expand All @@ -45,27 +41,23 @@
import org.apache.brooklyn.core.typereg.RegisteredTypeLoadingContexts;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.core.ResourceUtils;
import org.apache.brooklyn.util.core.config.ConfigBag;
import org.apache.brooklyn.util.stream.Streams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;

public class AbstractYamlRebindTest extends RebindTestFixture<StartableApplication> {

private static final Logger LOG = LoggerFactory.getLogger(AbstractYamlTest.class);
private static final Logger LOG = LoggerFactory.getLogger(AbstractYamlRebindTest.class);
protected static final String TEST_VERSION = "0.1.2";

protected BrooklynCampPlatform platform;
protected BrooklynCampPlatformLauncherNoServer launcher;
private boolean forceUpdate;

@BeforeMethod(alwaysRun = true)
@Override
public void setUp() throws Exception {
Expand Down Expand Up @@ -106,7 +98,7 @@ protected LocalManagementContext newMgmtContext() {
}
return result;
}

@Override
protected StartableApplication createApp() {
return null;
Expand All @@ -116,11 +108,11 @@ protected StartableApplication createApp() {
protected ManagementContext mgmt() {
return (newManagementContext != null) ? newManagementContext : origManagementContext;
}

///////////////////////////////////////////////////
// TODO code below is duplicate of AbstractYamlTest
///////////////////////////////////////////////////

protected void waitForApplicationTasks(Entity app) {
Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), app);
getLogger().info("Waiting on " + tasks.size() + " task(s)");
Expand Down Expand Up @@ -149,7 +141,7 @@ protected Entity createAndStartApplication(Reader input) throws Exception {
protected Entity createAndStartApplication(String... multiLineYaml) throws Exception {
return createAndStartApplication(joinLines(multiLineYaml));
}

protected Entity createAndStartApplication(String input) throws Exception {
return createAndStartApplication(input, MutableMap.<String,String>of());
}
Expand All @@ -168,18 +160,18 @@ protected Entity createAndStartApplication(String input, Map<String,?> startPara
protected Entity createStartWaitAndLogApplication(String... input) throws Exception {
return createStartWaitAndLogApplication(joinLines(input));
}

protected Entity createStartWaitAndLogApplication(String input) throws Exception {
return createStartWaitAndLogApplication(new StringReader(input));
}

protected Entity createStartWaitAndLogApplication(Reader input) throws Exception {
Entity app = createAndStartApplication(input);
waitForApplicationTasks(app);

getLogger().info("App started:");
Entities.dumpInfo(app);

return app;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.brooklyn.camp.brooklyn;

import static org.apache.brooklyn.test.Asserts.assertFalse;
import static org.testng.Assert.assertEquals;

import java.util.List;

import org.apache.brooklyn.api.effector.Effector;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.core.effector.CompositeEffector;
import org.apache.brooklyn.core.effector.http.HttpCommandEffector;
import org.apache.brooklyn.core.entity.EntityPredicates;
import org.apache.brooklyn.core.entity.StartableApplication;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.util.guava.Maybe;
import org.testng.annotations.Test;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;

@Test
public class CompositeEffectorYamlRebindTest extends AbstractYamlRebindTest {

private final static String appId = "my-app-with-composite-effector";
private final static String appVersion = "1.0.0-SNAPSHOT";
static final String appVersionedId = appId + ":" + appVersion;

static final String catalogYamlSimple = Joiner.on("\n").join(
"brooklyn.catalog:",
" id: " + appId,
" version: " + appVersion,
" itemType: entity",
" item:",
" type: " + TestEntity.class.getName(),
" name: targetEntity",
" brooklyn.initializers:",
" - type: " + HttpCommandEffector.class.getName(),
" brooklyn.config:",
" name: myEffector",
" description: myDescription",
" uri: https://httpbin.org/get?id=myId",
" httpVerb: GET",
" jsonPath: $.args.id",
" publishSensor: results",
" - type: " + CompositeEffector.class.getName(),
" brooklyn.config:",
" name: start",
" override: true",
" effectors:",
" - myEffector"
);

@Test
public void testRebindWhenHealthy() throws Exception {
runRebindWhenIsUp(catalogYamlSimple, appVersionedId);
}

protected void runRebindWhenIsUp(String catalogYaml, String appId) throws Exception {
addCatalogItems(catalogYaml);

String appYaml = Joiner.on("\n").join(
"services: ",
"- type: " + appId);
createStartWaitAndLogApplication(appYaml);

// Rebind
StartableApplication newApp = rebind();
TestEntity testEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity"));
Effector effector = assertHasInitializers(testEntity, "start");

// Confirm HttpCommandEffector still functions
Object results = testEntity.invoke(effector, ImmutableMap.<String, Object>of()).get();
assertEquals(((List<Object>)results).get(0), "myId");
}


protected static Effector<?> assertHasInitializers(Entity entity, String effectorName) {
Maybe<Effector<?>> effectorMaybe = entity.getEntityType().getEffectorByName(effectorName);
assertFalse(effectorMaybe.isAbsent());
return effectorMaybe.get();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.brooklyn.camp.brooklyn;

import static org.testng.Assert.assertEquals;

import java.util.List;

import org.apache.brooklyn.api.effector.Effector;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.core.effector.CompositeEffector;
import org.apache.brooklyn.core.effector.http.HttpCommandEffector;
import org.apache.brooklyn.entity.software.base.EmptySoftwareProcess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;

public class CompositeEffectorYamlTest extends AbstractYamlTest {
private static final Logger log = LoggerFactory.getLogger(CompositeEffectorYamlTest.class);

@Test
public void testCompositeEffector() throws Exception {
Entity app = createAndStartApplication(
"location: localhost",
"services:",
"- type: " + EmptySoftwareProcess.class.getName(),
" brooklyn.config:",
" onbox.base.dir.skipResolution: true",
" softwareProcess.serviceProcessIsRunningPollPeriod: forever",
" brooklyn.initializers:",
" - type: " + HttpCommandEffector.class.getName(),
" brooklyn.config:",
" name: myEffector",
" description: myDescription",
" uri: https://httpbin.org/get?id=myId",
" httpVerb: GET",
" jsonPath: $.args.id",
" publishSensor: results",
" - type: " + CompositeEffector.class.getName(),
" brooklyn.config:",
" name: start",
" override: true",
" effectors:",
" - myEffector"
);
waitForApplicationTasks(app);

EmptySoftwareProcess entity = (EmptySoftwareProcess) Iterables.getOnlyElement(app.getChildren());
Effector<?> effector = entity.getEntityType().getEffectorByName("start").get();

// Invoke without parameter
Object results = entity.invoke(effector, ImmutableMap.<String, Object>of()).get();
assertEquals(((List<Object>)results).get(0), "myId");
}

@Override
protected Logger getLogger() {
return log;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.brooklyn.camp.brooklyn;

import static org.apache.brooklyn.test.Asserts.assertFalse;
import static org.testng.Assert.assertEquals;

import org.apache.brooklyn.api.effector.Effector;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.core.effector.http.HttpCommandEffector;
import org.apache.brooklyn.core.entity.EntityPredicates;
import org.apache.brooklyn.core.entity.StartableApplication;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.util.guava.Maybe;
import org.testng.annotations.Test;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;

@Test
public class HttpCommandEffectorYamlRebindTest extends AbstractYamlRebindTest {

private final static String appId = "my-app-with-http-effector";
private final static String appVersion = "1.0.0-SNAPSHOT";
static final String appVersionedId = appId + ":" + appVersion;

static final String catalogYamlSimple = Joiner.on("\n").join(
"brooklyn.catalog:",
" id: " + appId,
" version: " + appVersion,
" itemType: entity",
" item:",
" type: " + TestEntity.class.getName(),
" name: targetEntity",
" brooklyn.initializers:",
" - type: " + HttpCommandEffector.class.getName(),
" brooklyn.config:",
" name: myEffector",
" description: myDescription",
" uri: https://httpbin.org/get?id=myId",
" httpVerb: GET",
" jsonPath: $.args.id",
" publishSensor: results");

@Test
public void testRebindWhenHealthy() throws Exception {
runRebindWhenIsUp(catalogYamlSimple, appVersionedId);
}

protected void runRebindWhenIsUp(String catalogYaml, String appId) throws Exception {
addCatalogItems(catalogYaml);

String appYaml = Joiner.on("\n").join(
"services: ",
"- type: " + appId);
createStartWaitAndLogApplication(appYaml);

// Rebind
StartableApplication newApp = rebind();
TestEntity testEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity"));
Effector effector = assertHasInitializers(testEntity, "myEffector");

// Confirm HttpCommandEffector still functions
Object result = testEntity.invoke(effector, ImmutableMap.<String, Object>of()).get();
assertEquals(((String)result).trim(), "myId");
}


protected static Effector<?> assertHasInitializers(Entity entity, String effectorName) {
Maybe<Effector<?>> effectorMaybe = entity.getEntityType().getEffectorByName(effectorName);
assertFalse(effectorMaybe.isAbsent());
return effectorMaybe.get();
}

}
Loading