From 9a351349933cf35abc4f3aa7764a5671646bb3a7 Mon Sep 17 00:00:00 2001 From: Valentin Aitken Date: Wed, 26 Apr 2017 10:15:35 +0300 Subject: [PATCH] Fix BROOKLYN-493 Rebind fails when using WinRmCommandSensor Add tests for CmdFeed rebind --- .../rebind/RebindAbstractCommandFeedTest.java | 61 +++++++++ .../rebind/RebindHistoricSshFeedTest.java | 46 +------ .../apache/brooklyn/feed/windows/CmdFeed.java | 6 + .../feed/windows/RebinWinrmCmdFeedTest.java | 38 ++++++ .../feed/windows/winrm-cmd-feed-a8pno3muco | 123 ++++++++++++++++++ ...nrm-cmd-feed-no-bundle-prefixes-akc24nlh2k | 121 +++++++++++++++++ 6 files changed, 350 insertions(+), 45 deletions(-) create mode 100644 core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindAbstractCommandFeedTest.java create mode 100644 software/winrm/src/test/java/org/apache/brooklyn/feed/windows/RebinWinrmCmdFeedTest.java create mode 100644 software/winrm/src/test/resources/org/apache/brooklyn/feed/windows/winrm-cmd-feed-a8pno3muco create mode 100644 software/winrm/src/test/resources/org/apache/brooklyn/feed/windows/winrm-cmd-feed-no-bundle-prefixes-akc24nlh2k diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindAbstractCommandFeedTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindAbstractCommandFeedTest.java new file mode 100644 index 0000000000..2c419a1627 --- /dev/null +++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindAbstractCommandFeedTest.java @@ -0,0 +1,61 @@ +/* + * 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.core.mgmt.rebind; + +import com.google.common.io.Files; +import org.apache.brooklyn.api.mgmt.rebind.RebindExceptionHandler; +import org.apache.brooklyn.api.mgmt.rebind.RebindManager; +import org.apache.brooklyn.api.objs.BrooklynObjectType; +import org.apache.brooklyn.core.test.entity.TestApplication; +import org.apache.brooklyn.util.os.Os; +import org.apache.brooklyn.util.stream.Streams; + +import java.io.File; + +public abstract class RebindAbstractCommandFeedTest extends RebindTestFixtureWithApp { + + @Override + protected TestApplication rebind() throws Exception { + RebindExceptionHandler exceptionHandler = RebindExceptionHandlerImpl.builder() + .danglingRefFailureMode(RebindManager.RebindFailureMode.FAIL_AT_END) + .rebindFailureMode(RebindManager.RebindFailureMode.FAIL_AT_END) + .addConfigFailureMode(RebindManager.RebindFailureMode.FAIL_AT_END) + .addPolicyFailureMode(RebindManager.RebindFailureMode.FAIL_AT_END) + .loadPolicyFailureMode(RebindManager.RebindFailureMode.FAIL_AT_END) + .build(); + return super.rebind(RebindOptions.create().exceptionHandler(exceptionHandler)); + } + + protected void addMemento(BrooklynObjectType type, String label, String id) throws Exception { + String mementoFilename = label+"-"+id; + String memento = Streams.readFullyString(getClass().getResourceAsStream(mementoFilename)); + + File persistedFile = getPersistanceFile(type, id); + Files.write(memento.getBytes(), persistedFile); + } + + protected File getPersistanceFile(BrooklynObjectType type, String id) { + String dir; + switch (type) { + case FEED: dir = "feeds"; break; + default: throw new UnsupportedOperationException("type="+type); + } + return new File(mementoDir, Os.mergePaths(dir, id)); + } +} diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindHistoricSshFeedTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindHistoricSshFeedTest.java index 548660cccd..a612bb0189 100644 --- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindHistoricSshFeedTest.java +++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindHistoricSshFeedTest.java @@ -18,26 +18,11 @@ */ package org.apache.brooklyn.core.mgmt.rebind; -import java.io.File; - -import org.apache.brooklyn.api.mgmt.rebind.RebindExceptionHandler; -import org.apache.brooklyn.api.mgmt.rebind.RebindManager.RebindFailureMode; import org.apache.brooklyn.api.objs.BrooklynObjectType; -import org.apache.brooklyn.core.test.entity.TestApplication; -import org.apache.brooklyn.util.os.Os; -import org.apache.brooklyn.util.stream.Streams; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import com.google.common.io.Files; - -public class RebindHistoricSshFeedTest extends RebindTestFixtureWithApp { - - @SuppressWarnings("unused") - private static final Logger log = LoggerFactory.getLogger(RebindHistoricSshFeedTest.class); - +public class RebindHistoricSshFeedTest extends RebindAbstractCommandFeedTest { @Override @BeforeMethod(alwaysRun=true) public void setUp() throws Exception { @@ -63,33 +48,4 @@ public void testFoo_2017_01_withoutBundlePrefixes() throws Exception { addMemento(BrooklynObjectType.FEED, "ssh-feed-no-bundle-prefixes", "zv7t8bim62"); rebind(); } - - @Override - protected TestApplication rebind() throws Exception { - RebindExceptionHandler exceptionHandler = RebindExceptionHandlerImpl.builder() - .danglingRefFailureMode(RebindFailureMode.FAIL_AT_END) - .rebindFailureMode(RebindFailureMode.FAIL_AT_END) - .addConfigFailureMode(RebindFailureMode.FAIL_AT_END) - .addPolicyFailureMode(RebindFailureMode.FAIL_AT_END) - .loadPolicyFailureMode(RebindFailureMode.FAIL_AT_END) - .build(); - return super.rebind(RebindOptions.create().exceptionHandler(exceptionHandler)); - } - - protected void addMemento(BrooklynObjectType type, String label, String id) throws Exception { - String mementoFilename = label+"-"+id; - String memento = Streams.readFullyString(getClass().getResourceAsStream(mementoFilename)); - - File persistedFile = getPersistanceFile(type, id); - Files.write(memento.getBytes(), persistedFile); - } - - protected File getPersistanceFile(BrooklynObjectType type, String id) { - String dir; - switch (type) { - case FEED: dir = "feeds"; break; - default: throw new UnsupportedOperationException("type="+type); - } - return new File(mementoDir, Os.mergePaths(dir, id)); - } } diff --git a/software/winrm/src/main/java/org/apache/brooklyn/feed/windows/CmdFeed.java b/software/winrm/src/main/java/org/apache/brooklyn/feed/windows/CmdFeed.java index 883b291caf..4cf3afbed0 100644 --- a/software/winrm/src/main/java/org/apache/brooklyn/feed/windows/CmdFeed.java +++ b/software/winrm/src/main/java/org/apache/brooklyn/feed/windows/CmdFeed.java @@ -62,6 +62,12 @@ public static CmdFeed.Builder builder() { return new CmdFeed.Builder(); } + /** + * For rebind; do not call directly; use builder + */ + public CmdFeed() { + } + protected CmdFeed(final Builder builder) { super(builder); } diff --git a/software/winrm/src/test/java/org/apache/brooklyn/feed/windows/RebinWinrmCmdFeedTest.java b/software/winrm/src/test/java/org/apache/brooklyn/feed/windows/RebinWinrmCmdFeedTest.java new file mode 100644 index 0000000000..dca9c0122f --- /dev/null +++ b/software/winrm/src/test/java/org/apache/brooklyn/feed/windows/RebinWinrmCmdFeedTest.java @@ -0,0 +1,38 @@ +/* + * 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.feed.windows; + +import org.apache.brooklyn.api.objs.BrooklynObjectType; +import org.apache.brooklyn.core.mgmt.rebind.RebindAbstractCommandFeedTest; +import org.testng.annotations.Test; + +public class RebinWinrmCmdFeedTest extends RebindAbstractCommandFeedTest { + + @Test + public void testSshFeed_2017_04() throws Exception { + addMemento(BrooklynObjectType.FEED, "winrm-cmd-feed", "a8pno3muco"); + rebind(); + } + + @Test + public void testSshFeed_2017_04_withoutBundlePrefixes() throws Exception { + addMemento(BrooklynObjectType.FEED, "winrm-cmd-feed-no-bundle-prefixes", "akc24nlh2k"); + rebind(); + } +} diff --git a/software/winrm/src/test/resources/org/apache/brooklyn/feed/windows/winrm-cmd-feed-a8pno3muco b/software/winrm/src/test/resources/org/apache/brooklyn/feed/windows/winrm-cmd-feed-a8pno3muco new file mode 100644 index 0000000000..5b13025776 --- /dev/null +++ b/software/winrm/src/test/resources/org/apache/brooklyn/feed/windows/winrm-cmd-feed-a8pno3muco @@ -0,0 +1,123 @@ + + + + 0.11.0-SNAPSHOT + org.apache.brooklyn.software-winrm:org.apache.brooklyn.feed.windows.CmdFeed + a8pno3muco + org.apache.brooklyn.feed.windows.CmdFeed + + CmdFeed[ssh[echo "test"->test.sensor]] + + CmdFeed[ssh[echo "test"->test.sensor]] + + true + + + + false + + + + + + 2 + 1 + + + + test.sensor + + 30000000000 + + java.lang.String + + java.lang.String + test.sensor + test.sensor + REQUIRED + + + + test.sensor + 30s + echo "test" + + + false + false + + echo "test" + + + + + + + + 1 + + 1 + + + + + + + + 1 + + + + + + + + + + + + + + + 0 + + + + + + false + true + 30000 + + + + + + 0 + + 0 + + + + + + + + diff --git a/software/winrm/src/test/resources/org/apache/brooklyn/feed/windows/winrm-cmd-feed-no-bundle-prefixes-akc24nlh2k b/software/winrm/src/test/resources/org/apache/brooklyn/feed/windows/winrm-cmd-feed-no-bundle-prefixes-akc24nlh2k new file mode 100644 index 0000000000..1e01745913 --- /dev/null +++ b/software/winrm/src/test/resources/org/apache/brooklyn/feed/windows/winrm-cmd-feed-no-bundle-prefixes-akc24nlh2k @@ -0,0 +1,121 @@ + + + + 0.11.0-SNAPSHOT + org.apache.brooklyn.feed.windows.CmdFeed + akc24nlh2k + org.apache.brooklyn.feed.windows.CmdFeed + + + CmdFeed[ssh[echo "test"->test.sensor]] + + CmdFeed[ssh[echo "test"->test.sensor]] + + + + + false + + + + + + 2 + 1 + + + + test.sensor + + 30000000000 + + java.lang.String + + java.lang.String + test.sensor + test.sensor + REQUIRED + + + + test.sensor + 30s + echo "test" + + + false + false + + echo "test" + + + + + + + + 0 + + 0 + + + + + 1 + + + + + + + + + + + + + + + 0 + + + + + + false + true + 30000 + + + + + + 0 + + 0 + + + + + + + true + +