BROOKLYN-162 - apply org.apache package prefix to software-base, tidying package names, and moving a few sensory things to core
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/64c2b2e5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/64c2b2e5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/64c2b2e5 Branch: refs/heads/master Commit: 64c2b2e5a31c86b44c08d77012b200595d46728c Parents: d326759 Author: Alex Heneveld <[email protected]> Authored: Tue Aug 18 22:12:56 2015 +0100 Committer: Alex Heneveld <[email protected]> Committed: Wed Aug 19 00:52:54 2015 +0100 ---------------------------------------------------------------------- .../brooklyn/sensor/core/HttpRequestSensor.java | 99 ++ .../brooklyn/sensor/core/StaticSensor.java | 72 ++ .../sensor/core/HttpRequestSensorTest.java | 85 ++ .../brooklyn/sensor/core/StaticSensorTest.java | 55 ++ .../brooklyn/demo/CumulusRDFApplication.java | 8 +- .../brooklyn/demo/ResilientMongoDbApp.java | 4 +- .../brooklyn/demo/NodeJsTodoApplication.java | 3 +- .../demo/WebClusterDatabaseExample.java | 2 +- .../demo/WebClusterDatabaseExampleApp.java | 4 +- ...lusterDatabaseExampleAppIntegrationTest.java | 4 +- .../basic/AbstractSoftwareProcessDriver.java | 516 ---------- .../basic/AbstractSoftwareProcessSshDriver.java | 658 ------------- .../AbstractSoftwareProcessWinRmDriver.java | 193 ---- .../entity/basic/AbstractVanillaProcess.java | 35 - .../entity/basic/EmptySoftwareProcess.java | 28 - .../basic/EmptySoftwareProcessDriver.java | 22 - .../entity/basic/EmptySoftwareProcessImpl.java | 39 - .../basic/EmptySoftwareProcessSshDriver.java | 83 -- .../SameServerDriverLifecycleEffectorTasks.java | 171 ---- .../brooklyn/entity/basic/SameServerEntity.java | 71 -- .../entity/basic/SameServerEntityImpl.java | 129 --- .../brooklyn/entity/basic/SoftwareProcess.java | 362 ------- .../entity/basic/SoftwareProcessDriver.java | 75 -- ...wareProcessDriverLifecycleEffectorTasks.java | 262 ----- .../entity/basic/SoftwareProcessImpl.java | 651 ------------- .../entity/basic/VanillaSoftwareProcess.java | 62 -- .../basic/VanillaSoftwareProcessDriver.java | 23 - .../basic/VanillaSoftwareProcessImpl.java | 37 - .../basic/VanillaSoftwareProcessSshDriver.java | 164 ---- .../entity/basic/VanillaWindowsProcess.java | 64 -- .../basic/VanillaWindowsProcessDriver.java | 23 - .../entity/basic/VanillaWindowsProcessImpl.java | 47 - .../basic/VanillaWindowsProcessWinRmDriver.java | 84 -- .../basic/lifecycle/NaiveScriptRunner.java | 43 - .../entity/basic/lifecycle/ScriptHelper.java | 436 --------- .../entity/basic/lifecycle/ScriptPart.java | 82 -- .../entity/brooklynnode/BrooklynCluster.java | 71 -- .../brooklynnode/BrooklynClusterImpl.java | 116 --- .../brooklynnode/BrooklynEntityMirror.java | 68 -- .../brooklynnode/BrooklynEntityMirrorImpl.java | 194 ---- .../entity/brooklynnode/BrooklynNode.java | 313 ------ .../entity/brooklynnode/BrooklynNodeDriver.java | 27 - .../entity/brooklynnode/BrooklynNodeImpl.java | 524 ---------- .../brooklynnode/BrooklynNodeSshDriver.java | 395 -------- .../entity/brooklynnode/EntityHttpClient.java | 93 -- .../brooklynnode/EntityHttpClientImpl.java | 162 ---- .../entity/brooklynnode/LocalBrooklynNode.java | 37 - .../brooklynnode/LocalBrooklynNodeImpl.java | 46 - .../brooklynnode/RemoteEffectorBuilder.java | 85 -- .../BrooklynClusterUpgradeEffectorBody.java | 207 ---- .../BrooklynNodeUpgradeEffectorBody.java | 230 ----- .../effector/SelectMasterEffectorBody.java | 175 ---- .../SetHighAvailabilityModeEffectorBody.java | 64 -- ...SetHighAvailabilityPriorityEffectorBody.java | 55 -- .../brooklyn/entity/chef/ChefAttributeFeed.java | 410 -------- .../entity/chef/ChefAttributePollConfig.java | 53 -- .../brooklyn/entity/chef/ChefBashCommands.java | 42 - .../java/brooklyn/entity/chef/ChefConfig.java | 98 -- .../java/brooklyn/entity/chef/ChefConfigs.java | 102 -- .../java/brooklyn/entity/chef/ChefEntity.java | 27 - .../brooklyn/entity/chef/ChefEntityImpl.java | 38 - .../entity/chef/ChefLifecycleEffectorTasks.java | 362 ------- .../brooklyn/entity/chef/ChefServerTasks.java | 97 -- .../brooklyn/entity/chef/ChefSoloDriver.java | 87 -- .../brooklyn/entity/chef/ChefSoloTasks.java | 71 -- .../java/brooklyn/entity/chef/ChefTasks.java | 154 --- .../entity/chef/KnifeConvergeTaskFactory.java | 246 ----- .../brooklyn/entity/chef/KnifeTaskFactory.java | 240 ----- .../java/brooklyn/entity/java/JavaAppUtils.java | 264 ----- .../brooklyn/entity/java/JavaEntityMethods.java | 30 - .../entity/java/JavaSoftwareProcessDriver.java | 30 - .../java/JavaSoftwareProcessSshDriver.java | 444 --------- .../java/brooklyn/entity/java/JmxSupport.java | 359 ------- .../brooklyn/entity/java/JmxmpSslSupport.java | 134 --- .../java/brooklyn/entity/java/UsesJava.java | 68 -- .../brooklyn/entity/java/UsesJavaMXBeans.java | 77 -- .../main/java/brooklyn/entity/java/UsesJmx.java | 190 ---- .../brooklyn/entity/java/VanillaJavaApp.java | 78 -- .../entity/java/VanillaJavaAppDriver.java | 26 - .../entity/java/VanillaJavaAppImpl.java | 113 --- .../entity/java/VanillaJavaAppSshDriver.java | 212 ----- .../entity/machine/MachineAttributes.java | 87 -- .../brooklyn/entity/machine/MachineEntity.java | 60 -- .../entity/machine/MachineEntityImpl.java | 184 ---- .../java/brooklyn/entity/pool/ServerPool.java | 111 --- .../brooklyn/entity/pool/ServerPoolImpl.java | 432 --------- .../entity/pool/ServerPoolLocation.java | 82 -- .../entity/pool/ServerPoolLocationResolver.java | 138 --- .../entity/service/EntityLaunchListener.java | 111 --- .../entity/service/InitdServiceInstaller.java | 137 --- .../entity/service/SystemServiceEnricher.java | 154 --- .../entity/service/SystemServiceInstaller.java | 25 - .../service/SystemServiceInstallerFactory.java | 28 - .../entity/software/MachineInitTasks.java | 172 ---- .../software/MachineLifecycleEffectorTasks.java | 949 ------------------ .../software/ProvidesProvisioningFlags.java | 34 - .../entity/software/SshEffectorTasks.java | 336 ------- .../brooklyn/entity/software/StaticSensor.java | 72 -- .../entity/software/http/HttpRequestSensor.java | 99 -- .../software/java/JmxAttributeSensor.java | 123 --- .../entity/software/ssh/SshCommandEffector.java | 104 -- .../entity/software/ssh/SshCommandSensor.java | 143 --- .../winrm/WindowsPerformanceCounterSensors.java | 73 -- .../event/feed/jmx/JmxAttributePollConfig.java | 74 -- .../java/brooklyn/event/feed/jmx/JmxFeed.java | 437 --------- .../java/brooklyn/event/feed/jmx/JmxHelper.java | 725 -------------- .../event/feed/jmx/JmxNotificationFilters.java | 64 -- .../jmx/JmxNotificationSubscriptionConfig.java | 95 -- .../event/feed/jmx/JmxOperationPollConfig.java | 121 --- .../event/feed/jmx/JmxValueFunctions.java | 95 -- .../entity/brooklynnode/BrooklynCluster.java | 70 ++ .../brooklynnode/BrooklynClusterImpl.java | 115 +++ .../brooklynnode/BrooklynEntityMirror.java | 67 ++ .../brooklynnode/BrooklynEntityMirrorImpl.java | 194 ++++ .../entity/brooklynnode/BrooklynNode.java | 312 ++++++ .../entity/brooklynnode/BrooklynNodeDriver.java | 27 + .../entity/brooklynnode/BrooklynNodeImpl.java | 522 ++++++++++ .../brooklynnode/BrooklynNodeSshDriver.java | 394 ++++++++ .../entity/brooklynnode/EntityHttpClient.java | 93 ++ .../brooklynnode/EntityHttpClientImpl.java | 162 ++++ .../entity/brooklynnode/LocalBrooklynNode.java | 37 + .../brooklynnode/LocalBrooklynNodeImpl.java | 46 + .../brooklynnode/RemoteEffectorBuilder.java | 84 ++ .../BrooklynClusterUpgradeEffectorBody.java | 206 ++++ .../BrooklynNodeUpgradeEffectorBody.java | 229 +++++ .../effector/SelectMasterEffectorBody.java | 174 ++++ .../SetHighAvailabilityModeEffectorBody.java | 63 ++ ...SetHighAvailabilityPriorityEffectorBody.java | 54 ++ .../brooklyn/entity/chef/ChefAttributeFeed.java | 410 ++++++++ .../entity/chef/ChefAttributePollConfig.java | 53 ++ .../brooklyn/entity/chef/ChefBashCommands.java | 42 + .../apache/brooklyn/entity/chef/ChefConfig.java | 98 ++ .../brooklyn/entity/chef/ChefConfigs.java | 102 ++ .../apache/brooklyn/entity/chef/ChefEntity.java | 26 + .../brooklyn/entity/chef/ChefEntityImpl.java | 38 + .../entity/chef/ChefLifecycleEffectorTasks.java | 360 +++++++ .../brooklyn/entity/chef/ChefServerTasks.java | 97 ++ .../brooklyn/entity/chef/ChefSoloDriver.java | 85 ++ .../brooklyn/entity/chef/ChefSoloTasks.java | 70 ++ .../apache/brooklyn/entity/chef/ChefTasks.java | 153 +++ .../entity/chef/KnifeConvergeTaskFactory.java | 246 +++++ .../brooklyn/entity/chef/KnifeTaskFactory.java | 240 +++++ .../brooklyn/entity/java/JavaAppUtils.java | 263 +++++ .../brooklyn/entity/java/JavaEntityMethods.java | 30 + .../entity/java/JavaSoftwareProcessDriver.java | 30 + .../java/JavaSoftwareProcessSshDriver.java | 443 +++++++++ .../entity/java/JmxAttributeSensor.java | 121 +++ .../apache/brooklyn/entity/java/JmxSupport.java | 357 +++++++ .../brooklyn/entity/java/JmxmpSslSupport.java | 134 +++ .../apache/brooklyn/entity/java/UsesJava.java | 68 ++ .../brooklyn/entity/java/UsesJavaMXBeans.java | 77 ++ .../apache/brooklyn/entity/java/UsesJmx.java | 190 ++++ .../brooklyn/entity/java/VanillaJavaApp.java | 77 ++ .../entity/java/VanillaJavaAppDriver.java | 26 + .../entity/java/VanillaJavaAppImpl.java | 112 +++ .../entity/java/VanillaJavaAppSshDriver.java | 211 ++++ .../entity/machine/MachineAttributes.java | 87 ++ .../brooklyn/entity/machine/MachineEntity.java | 59 ++ .../entity/machine/MachineEntityImpl.java | 182 ++++ .../entity/machine/MachineInitTasks.java | 172 ++++ .../machine/ProvidesProvisioningFlags.java | 35 + .../entity/machine/pool/ServerPool.java | 109 +++ .../entity/machine/pool/ServerPoolImpl.java | 432 +++++++++ .../entity/machine/pool/ServerPoolLocation.java | 82 ++ .../pool/ServerPoolLocationResolver.java | 138 +++ .../base/AbstractSoftwareProcessDriver.java | 516 ++++++++++ .../base/AbstractSoftwareProcessSshDriver.java | 657 +++++++++++++ .../AbstractSoftwareProcessWinRmDriver.java | 193 ++++ .../software/base/AbstractVanillaProcess.java | 35 + .../software/base/EmptySoftwareProcess.java | 28 + .../base/EmptySoftwareProcessDriver.java | 22 + .../software/base/EmptySoftwareProcessImpl.java | 39 + .../base/EmptySoftwareProcessSshDriver.java | 83 ++ .../SameServerDriverLifecycleEffectorTasks.java | 170 ++++ .../entity/software/base/SameServerEntity.java | 71 ++ .../software/base/SameServerEntityImpl.java | 128 +++ .../entity/software/base/SoftwareProcess.java | 362 +++++++ .../software/base/SoftwareProcessDriver.java | 75 ++ ...wareProcessDriverLifecycleEffectorTasks.java | 261 +++++ .../software/base/SoftwareProcessImpl.java | 651 +++++++++++++ .../software/base/VanillaSoftwareProcess.java | 62 ++ .../base/VanillaSoftwareProcessDriver.java | 23 + .../base/VanillaSoftwareProcessImpl.java | 37 + .../base/VanillaSoftwareProcessSshDriver.java | 162 ++++ .../software/base/VanillaWindowsProcess.java | 64 ++ .../base/VanillaWindowsProcessDriver.java | 23 + .../base/VanillaWindowsProcessImpl.java | 47 + .../base/VanillaWindowsProcessWinRmDriver.java | 84 ++ .../MachineLifecycleEffectorTasks.java | 951 +++++++++++++++++++ .../base/lifecycle/NaiveScriptRunner.java | 43 + .../software/base/lifecycle/ScriptHelper.java | 436 +++++++++ .../software/base/lifecycle/ScriptPart.java | 82 ++ .../system_service/EntityLaunchListener.java | 111 +++ .../system_service/InitdServiceInstaller.java | 135 +++ .../system_service/SystemServiceEnricher.java | 152 +++ .../system_service/SystemServiceInstaller.java | 25 + .../SystemServiceInstallerFactory.java | 28 + .../sensor/feed/jmx/JmxAttributePollConfig.java | 74 ++ .../brooklyn/sensor/feed/jmx/JmxFeed.java | 436 +++++++++ .../brooklyn/sensor/feed/jmx/JmxHelper.java | 724 ++++++++++++++ .../sensor/feed/jmx/JmxNotificationFilters.java | 64 ++ .../jmx/JmxNotificationSubscriptionConfig.java | 95 ++ .../sensor/feed/jmx/JmxOperationPollConfig.java | 121 +++ .../sensor/feed/jmx/JmxValueFunctions.java | 95 ++ .../brooklyn/sensor/ssh/SshCommandEffector.java | 102 ++ .../brooklyn/sensor/ssh/SshCommandSensor.java | 142 +++ .../brooklyn/sensor/ssh/SshEffectorTasks.java | 334 +++++++ .../winrm/WindowsPerformanceCounterSensors.java | 73 ++ .../entity/brooklynnode/brooklyn-cluster.yaml | 33 - .../brooklyn-node-persisting-to-tmp.yaml | 27 - .../entity/brooklynnode/brooklyn-node.yaml | 35 - .../brooklyn/entity/service/service.sh | 51 - .../entity/brooklynnode/brooklyn-cluster.yaml | 33 + .../brooklyn-node-persisting-to-tmp.yaml | 27 + .../entity/brooklynnode/brooklyn-node.yaml | 35 + .../brooklyn/entity/system_service/service.sh | 51 + .../brooklyn/entity/AbstractEc2LiveTest.java | 139 --- .../entity/AbstractGoogleComputeLiveTest.java | 137 --- .../entity/AbstractSoftlayerLiveTest.java | 115 --- ...ctSoftwareProcessRestartIntegrationTest.java | 97 -- .../entity/basic/DoNothingSoftwareProcess.java | 32 - .../basic/DoNothingSoftwareProcessDriver.java | 68 -- .../basic/DoNothingSoftwareProcessImpl.java | 37 - .../entity/basic/SameServerEntityTest.java | 83 -- .../basic/SoftwareProcessEntityLatchTest.java | 162 ---- .../basic/SoftwareProcessEntityRebindTest.java | 181 ---- .../entity/basic/SoftwareProcessEntityTest.java | 793 ---------------- ...SoftwareProcessSshDriverIntegrationTest.java | 385 -------- .../basic/SoftwareProcessSubclassTest.java | 166 ---- ...ftwareProcessAndChildrenIntegrationTest.java | 196 ---- .../entity/basic/lifecycle/MyEntity.java | 28 - .../entity/basic/lifecycle/MyEntityApp.java | 26 - .../entity/basic/lifecycle/MyEntityImpl.java | 126 --- .../basic/lifecycle/NaiveScriptRunnerTest.java | 252 ----- .../basic/lifecycle/ScriptHelperTest.java | 159 ---- .../basic/lifecycle/StartStopSshDriverTest.java | 170 ---- .../BrooklynClusterIntegrationTest.java | 97 -- .../BrooklynNodeIntegrationTest.java | 630 ------------ .../entity/brooklynnode/BrooklynNodeTest.java | 138 --- .../brooklynnode/CallbackEntityHttpClient.java | 101 -- .../entity/brooklynnode/MockBrooklynNode.java | 71 -- .../brooklynnode/SameBrooklynNodeImpl.java | 96 -- .../brooklynnode/SelectMasterEffectorTest.java | 257 ----- .../brooklyn/entity/chef/ChefConfigsTest.java | 50 - .../entity/chef/ChefLiveTestSupport.java | 98 -- .../chef/ChefServerTasksIntegrationTest.java | 124 --- .../AbstractChefToyMySqlEntityLiveTest.java | 42 - .../ChefSoloDriverMySqlEntityLiveTest.java | 50 - .../mysql/ChefSoloDriverToyMySqlEntity.java | 90 -- ...micChefAutodetectToyMySqlEntityLiveTest.java | 43 - ...DynamicChefServerToyMySqlEntityLiveTest.java | 51 - .../DynamicChefSoloToyMySqlEntityLiveTest.java | 43 - .../chef/mysql/DynamicToyMySqlEntityChef.java | 82 -- .../chef/mysql/TypedToyMySqlEntityChef.java | 56 -- .../brooklyn/entity/driver/MockSshDriver.java | 74 -- ...rWithAvailabilityZonesMultiLocationTest.java | 117 --- .../brooklyn/entity/java/EntityPollingTest.java | 206 ---- .../entity/java/ExampleVanillaMain.java | 26 - .../java/ExampleVanillaMainCpuHungry.java | 41 - .../java/brooklyn/entity/java/JavaOptsTest.java | 357 ------- ...SoftwareProcessSshDriverIntegrationTest.java | 174 ---- .../brooklyn/entity/java/JmxSupportTest.java | 135 --- .../brooklyn/entity/java/SslKeyConfigTest.java | 53 -- .../entity/java/VanillaJavaAppRebindTest.java | 173 ---- .../entity/java/VanillaJavaAppTest.java | 350 ------- .../machine/MachineEntityEc2LiveTest.java | 57 -- .../entity/machine/MachineEntityRebindTest.java | 45 - .../entity/pool/AbstractServerPoolTest.java | 146 --- .../entity/pool/ServerPoolLiveTest.java | 97 -- .../pool/ServerPoolLocationResolverTest.java | 89 -- .../entity/pool/ServerPoolRebindTest.java | 108 --- .../brooklyn/entity/pool/ServerPoolTest.java | 174 ---- .../service/SystemServiceEnricherTest.java | 96 -- .../entity/software/AbstractDockerLiveTest.java | 99 -- .../MachineLifecycleEffectorTasksTest.java | 140 --- .../entity/software/SoftwareEffectorTest.java | 142 --- .../entity/software/SshEffectorTasksTest.java | 263 ----- .../entity/software/StaticSensorTest.java | 54 -- .../software/http/HttpRequestSensorTest.java | 84 -- .../mysql/AbstractToyMySqlEntityTest.java | 109 --- .../mysql/DynamicToyMySqlEntityBuilder.java | 191 ---- .../mysql/DynamicToyMySqlEntityTest.java | 58 -- .../software/ssh/SshCommandIntegrationTest.java | 124 --- .../PortAttributeSensorAndConfigKeyTest.java | 88 -- .../brooklyn/event/feed/jmx/JmxFeedTest.java | 418 -------- .../brooklyn/event/feed/jmx/JmxHelperTest.java | 311 ------ .../event/feed/jmx/RebindJmxFeedTest.java | 148 --- .../usage/ApplicationUsageTrackingTest.java | 224 ----- .../usage/LocationUsageTrackingTest.java | 212 ----- .../usage/RecordingLegacyUsageListener.java | 70 -- .../usage/RecordingUsageListener.java | 67 -- .../management/usage/UsageListenerTest.java | 142 --- .../brooklyn/test/GeneralisedDynamicMBean.java | 146 --- .../src/test/java/brooklyn/test/JmxService.java | 173 ---- .../brooklyn/entity/AbstractEc2LiveTest.java | 139 +++ .../entity/AbstractGoogleComputeLiveTest.java | 137 +++ .../entity/AbstractSoftlayerLiveTest.java | 115 +++ .../BrooklynClusterIntegrationTest.java | 97 ++ .../BrooklynNodeIntegrationTest.java | 632 ++++++++++++ .../entity/brooklynnode/BrooklynNodeTest.java | 141 +++ .../brooklynnode/CallbackEntityHttpClient.java | 100 ++ .../entity/brooklynnode/MockBrooklynNode.java | 72 ++ .../brooklynnode/SameBrooklynNodeImpl.java | 97 ++ .../brooklynnode/SelectMasterEffectorTest.java | 259 +++++ .../brooklyn/entity/chef/ChefConfigsTest.java | 52 + .../entity/chef/ChefLiveTestSupport.java | 99 ++ .../chef/ChefServerTasksIntegrationTest.java | 126 +++ .../AbstractChefToyMySqlEntityLiveTest.java | 40 + .../ChefSoloDriverMySqlEntityLiveTest.java | 49 + .../mysql/ChefSoloDriverToyMySqlEntity.java | 89 ++ ...micChefAutodetectToyMySqlEntityLiveTest.java | 43 + ...DynamicChefServerToyMySqlEntityLiveTest.java | 50 + .../DynamicChefSoloToyMySqlEntityLiveTest.java | 43 + .../chef/mysql/DynamicToyMySqlEntityChef.java | 81 ++ .../chef/mysql/TypedToyMySqlEntityChef.java | 55 ++ .../brooklyn/entity/java/EntityPollingTest.java | 206 ++++ .../entity/java/ExampleVanillaMain.java | 26 + .../java/ExampleVanillaMainCpuHungry.java | 41 + .../brooklyn/entity/java/JavaOptsTest.java | 361 +++++++ ...SoftwareProcessSshDriverIntegrationTest.java | 173 ++++ .../brooklyn/entity/java/JmxSupportTest.java | 135 +++ .../brooklyn/entity/java/SslKeyConfigTest.java | 53 ++ .../entity/java/VanillaJavaAppRebindTest.java | 173 ++++ .../entity/java/VanillaJavaAppTest.java | 352 +++++++ .../machine/MachineEntityEc2LiveTest.java | 57 ++ .../entity/machine/MachineEntityRebindTest.java | 44 + .../machine/pool/AbstractServerPoolTest.java | 145 +++ .../entity/machine/pool/ServerPoolLiveTest.java | 97 ++ .../pool/ServerPoolLocationResolverTest.java | 90 ++ .../machine/pool/ServerPoolRebindTest.java | 109 +++ .../entity/machine/pool/ServerPoolTest.java | 175 ++++ .../software/base/AbstractDockerLiveTest.java | 99 ++ ...ctSoftwareProcessRestartIntegrationTest.java | 96 ++ .../software/base/DoNothingSoftwareProcess.java | 33 + .../base/DoNothingSoftwareProcessDriver.java | 69 ++ .../base/DoNothingSoftwareProcessImpl.java | 38 + .../base/MachineLifecycleEffectorTasksTest.java | 140 +++ .../software/base/SameServerEntityTest.java | 84 ++ .../software/base/SoftwareEffectorTest.java | 141 +++ .../base/SoftwareProcessEntityLatchTest.java | 161 ++++ .../base/SoftwareProcessEntityRebindTest.java | 179 ++++ .../base/SoftwareProcessEntityTest.java | 798 ++++++++++++++++ ...SoftwareProcessSshDriverIntegrationTest.java | 389 ++++++++ .../base/SoftwareProcessSubclassTest.java | 169 ++++ ...ftwareProcessAndChildrenIntegrationTest.java | 197 ++++ .../software/base/lifecycle/MyEntity.java | 27 + .../software/base/lifecycle/MyEntityApp.java | 26 + .../software/base/lifecycle/MyEntityImpl.java | 125 +++ .../base/lifecycle/NaiveScriptRunnerTest.java | 254 +++++ .../base/lifecycle/ScriptHelperTest.java | 157 +++ .../base/lifecycle/StartStopSshDriverTest.java | 168 ++++ .../usage/ApplicationUsageTrackingTest.java | 224 +++++ .../mgmt/usage/LocationUsageTrackingTest.java | 210 ++++ .../usage/RecordingLegacyUsageListener.java | 70 ++ .../core/mgmt/usage/RecordingUsageListener.java | 67 ++ .../test/core/mgmt/usage/UsageListenerTest.java | 142 +++ .../base/test/driver/MockSshDriver.java | 72 ++ ...rWithAvailabilityZonesMultiLocationTest.java | 115 +++ .../base/test/jmx/GeneralisedDynamicMBean.java | 146 +++ .../software/base/test/jmx/JmxService.java | 172 ++++ .../location/MachineDetailsEc2LiveTest.java | 70 ++ .../MachineDetailsGoogleComputeLiveTest.java | 67 ++ .../location/WinRmMachineLocationLiveTest.java | 92 ++ .../test/location/WinRmMachineLocationTest.java | 44 + .../test/mysql/AbstractToyMySqlEntityTest.java | 107 +++ .../mysql/DynamicToyMySqlEntityBuilder.java | 189 ++++ .../test/mysql/DynamicToyMySqlEntityTest.java | 58 ++ .../PortAttributeSensorAndConfigKeyTest.java | 86 ++ .../test/ssh/SshCommandIntegrationTest.java | 126 +++ .../SystemServiceEnricherTest.java | 95 ++ .../basic/MachineDetailsEc2LiveTest.java | 68 -- .../MachineDetailsGoogleComputeLiveTest.java | 65 -- .../basic/WinRmMachineLocationLiveTest.java | 92 -- .../basic/WinRmMachineLocationTest.java | 43 - .../brooklyn/sensor/feed/jmx/JmxFeedTest.java | 422 ++++++++ .../brooklyn/sensor/feed/jmx/JmxHelperTest.java | 311 ++++++ .../sensor/feed/jmx/RebindJmxFeedTest.java | 148 +++ .../sensor/ssh/SshEffectorTasksTest.java | 264 +++++ .../resources/brooklyn/entity/basic/frogs.txt | 27 - .../brooklyn/entity/basic/template.yaml | 23 - .../basic/template_with_extra_substitutions.txt | 18 - .../brooklyn-tests.pem | 27 - .../brooklyn-validator.pem | 27 - .../hosted-chef-brooklyn-credentials/knife.rb | 27 - .../brooklyn-tests.pem | 27 + .../brooklyn-validator.pem | 27 + .../hosted-chef-brooklyn-credentials/knife.rb | 27 + .../brooklyn/entity/software/base/frogs.txt | 27 + .../brooklyn/entity/software/base/template.yaml | 23 + .../base/template_with_extra_substitutions.txt | 18 + .../entity/database/crate/CrateNode.java | 12 +- .../entity/database/crate/CrateNodeDriver.java | 2 +- .../entity/database/crate/CrateNodeImpl.java | 7 +- .../database/crate/CrateNodeSshDriver.java | 3 +- .../entity/database/mariadb/MariaDbDriver.java | 3 +- .../entity/database/mariadb/MariaDbNode.java | 4 +- .../database/mariadb/MariaDbNodeImpl.java | 4 +- .../database/mariadb/MariaDbSshDriver.java | 8 +- .../entity/database/mysql/MySqlDriver.java | 3 +- .../entity/database/mysql/MySqlNode.java | 4 +- .../entity/database/mysql/MySqlNodeImpl.java | 4 +- .../entity/database/mysql/MySqlSshDriver.java | 8 +- .../database/postgresql/PostgreSqlDriver.java | 5 +- .../database/postgresql/PostgreSqlNode.java | 4 +- .../PostgreSqlNodeChefImplFromScratch.java | 10 +- .../database/postgresql/PostgreSqlNodeImpl.java | 3 +- .../database/postgresql/PostgreSqlSpecs.java | 5 +- .../postgresql/PostgreSqlSshDriver.java | 9 +- .../entity/database/rubyrep/RubyRepDriver.java | 2 +- .../entity/database/rubyrep/RubyRepNode.java | 4 +- .../database/rubyrep/RubyRepNodeImpl.java | 3 +- .../database/rubyrep/RubyRepSshDriver.java | 4 +- .../brooklyn/entity/database/mssql/mssql.yaml | 2 +- .../database/mariadb/MariaDbLiveEc2Test.java | 4 +- .../database/mysql/MySqlClusterLiveEc2Test.java | 4 +- .../mysql/MySqlClusterLiveSoftlayerTest.java | 4 +- .../entity/database/mysql/MySqlLiveEc2Test.java | 4 +- .../entity/database/mysql/MySqlLiveGceTest.java | 4 +- .../mysql/MySqlRestartIntegrationTest.java | 5 +- .../database/mysql/MysqlDockerLiveTest.java | 3 +- .../postgresql/PostgreSqDockerLiveTest.java | 3 +- .../database/postgresql/PostgreSqlChefTest.java | 8 +- .../postgresql/PostgreSqlEc2LiveTest.java | 4 +- .../postgresql/PostgreSqlGceLiveTest.java | 4 +- .../PostgreSqlRestartIntegrationTest.java | 5 +- .../database/rubyrep/RubyRepEc2LiveTest.java | 4 +- .../messaging/activemq/ActiveMQBroker.java | 6 +- .../messaging/activemq/ActiveMQBrokerImpl.java | 9 +- .../activemq/ActiveMQDestinationImpl.java | 5 +- .../messaging/activemq/ActiveMQDriver.java | 2 +- .../messaging/activemq/ActiveMQQueueImpl.java | 5 +- .../messaging/activemq/ActiveMQSshDriver.java | 3 +- .../entity/messaging/jms/JMSBroker.java | 2 +- .../entity/messaging/jms/JMSBrokerImpl.java | 4 +- .../kafka/AbstractfKafkaSshDriver.java | 4 +- .../brooklyn/entity/messaging/kafka/Kafka.java | 3 +- .../entity/messaging/kafka/KafkaBroker.java | 6 +- .../messaging/kafka/KafkaBrokerDriver.java | 2 +- .../entity/messaging/kafka/KafkaBrokerImpl.java | 11 +- .../messaging/kafka/KafkaBrokerSshDriver.java | 6 +- .../entity/messaging/kafka/KafkaZooKeeper.java | 4 +- .../messaging/kafka/KafkaZooKeeperDriver.java | 2 +- .../entity/messaging/qpid/QpidBroker.java | 6 +- .../entity/messaging/qpid/QpidBrokerImpl.java | 11 +- .../messaging/qpid/QpidDestinationImpl.java | 9 +- .../entity/messaging/qpid/QpidDriver.java | 2 +- .../entity/messaging/qpid/QpidQueueImpl.java | 5 +- .../entity/messaging/qpid/QpidSshDriver.java | 4 +- .../entity/messaging/rabbit/RabbitBroker.java | 4 +- .../messaging/rabbit/RabbitBrokerImpl.java | 3 +- .../entity/messaging/rabbit/RabbitDriver.java | 2 +- .../messaging/rabbit/RabbitSshDriver.java | 5 +- .../brooklyn/entity/messaging/storm/Storm.java | 6 +- .../entity/messaging/storm/StormDriver.java | 2 +- .../entity/messaging/storm/StormImpl.java | 11 +- .../entity/messaging/storm/StormSshDriver.java | 6 +- .../entity/zookeeper/AbstractZooKeeperImpl.java | 11 +- .../entity/zookeeper/ZooKeeperDriver.java | 2 +- .../entity/zookeeper/ZooKeeperNode.java | 3 +- .../entity/zookeeper/ZooKeeperSshDriver.java | 4 +- .../messaging/activemq/ActiveMQEc2LiveTest.java | 3 +- .../activemq/ActiveMQGoogleComputeLiveTest.java | 3 +- .../activemq/ActiveMQIntegrationTest.java | 5 +- .../entity/messaging/kafka/KafkaLiveTest.java | 3 +- .../entity/messaging/qpid/QpidEc2LiveTest.java | 3 +- .../messaging/qpid/QpidIntegrationTest.java | 3 +- .../messaging/rabbit/RabbitEc2LiveTest.java | 4 +- .../messaging/storm/StormEc2LiveTest.java | 4 +- .../zookeeper/ZooKeeperEc2LiveTest.java | 4 +- .../entity/monitoring/monit/MonitDriver.java | 2 +- .../entity/monitoring/monit/MonitNode.java | 3 +- .../entity/monitoring/monit/MonitNodeImpl.java | 3 +- .../entity/monitoring/monit/MonitSshDriver.java | 5 +- .../monitoring/monit/MonitIntegrationTest.java | 5 +- .../entity/network/bind/BindDnsServer.java | 4 +- .../network/bind/BindDnsServerDriver.java | 4 +- .../entity/network/bind/BindDnsServerImpl.java | 3 +- .../network/bind/BindDnsServerSshDriver.java | 3 +- .../network/bind/BindDnsServerEc2LiveTest.java | 4 +- .../bind/BindDnsServerIntegrationTest.java | 3 +- .../network/bind/BindDnsServerLiveTest.java | 5 +- .../bind/BindDnsServerSoftlayerLiveTest.java | 4 +- .../bind/DoNothingSoftwareProcessDriver.java | 6 +- .../entity/nosql/cassandra/CassandraNode.java | 10 +- .../nosql/cassandra/CassandraNodeDriver.java | 3 +- .../nosql/cassandra/CassandraNodeImpl.java | 14 +- .../nosql/cassandra/CassandraNodeSshDriver.java | 8 +- .../nosql/couchbase/CouchbaseClusterImpl.java | 4 +- .../entity/nosql/couchbase/CouchbaseNode.java | 3 +- .../nosql/couchbase/CouchbaseNodeDriver.java | 3 +- .../nosql/couchbase/CouchbaseNodeImpl.java | 4 +- .../nosql/couchbase/CouchbaseNodeSshDriver.java | 6 +- .../nosql/couchbase/CouchbaseSyncGateway.java | 3 +- .../couchbase/CouchbaseSyncGatewayDriver.java | 2 +- .../couchbase/CouchbaseSyncGatewayImpl.java | 3 +- .../CouchbaseSyncGatewaySshDriver.java | 4 +- .../entity/nosql/couchdb/CouchDBNode.java | 3 +- .../entity/nosql/couchdb/CouchDBNodeDriver.java | 2 +- .../entity/nosql/couchdb/CouchDBNodeImpl.java | 3 +- .../nosql/couchdb/CouchDBNodeSshDriver.java | 4 +- .../nosql/elasticsearch/ElasticSearchNode.java | 4 +- .../elasticsearch/ElasticSearchNodeDriver.java | 2 +- .../elasticsearch/ElasticSearchNodeImpl.java | 4 +- .../ElasticSearchNodeSshDriver.java | 4 +- .../nosql/mongodb/AbstractMongoDBServer.java | 3 +- .../nosql/mongodb/AbstractMongoDBSshDriver.java | 6 +- .../nosql/mongodb/MongoDBClientDriver.java | 2 +- .../entity/nosql/mongodb/MongoDBClientImpl.java | 3 +- .../entity/nosql/mongodb/MongoDBDriver.java | 2 +- .../entity/nosql/mongodb/MongoDBServerImpl.java | 4 +- .../sharding/CoLocatedMongoDBRouter.java | 3 +- .../sharding/CoLocatedMongoDBRouterImpl.java | 3 +- .../sharding/MongoDBConfigServerDriver.java | 2 +- .../sharding/MongoDBConfigServerImpl.java | 2 +- .../mongodb/sharding/MongoDBRouterDriver.java | 2 +- .../mongodb/sharding/MongoDBRouterImpl.java | 3 +- .../brooklyn/entity/nosql/redis/RedisStore.java | 3 +- .../entity/nosql/redis/RedisStoreDriver.java | 2 +- .../entity/nosql/redis/RedisStoreImpl.java | 4 +- .../entity/nosql/redis/RedisStoreSshDriver.java | 4 +- .../brooklyn/entity/nosql/riak/RiakNode.java | 5 +- .../entity/nosql/riak/RiakNodeDriver.java | 4 +- .../entity/nosql/riak/RiakNodeImpl.java | 4 +- .../entity/nosql/riak/RiakNodeSshDriver.java | 9 +- .../brooklyn/entity/nosql/solr/SolrServer.java | 10 +- .../entity/nosql/solr/SolrServerDriver.java | 4 +- .../entity/nosql/solr/SolrServerImpl.java | 3 +- .../entity/nosql/solr/SolrServerSshDriver.java | 5 +- .../cassandra/CassandraDatacenterTest.java | 6 +- .../nosql/cassandra/CassandraFabricTest.java | 4 +- .../cassandra/CassandraNodeEc2LiveTest.java | 3 +- .../CouchbaseSyncGatewayEc2LiveTest.java | 3 +- .../nosql/couchdb/CouchDBNodeEc2LiveTest.java | 3 +- .../nosql/mongodb/MongoDBEc2LiveTest.java | 3 +- .../mongodb/MongoDBReplicaSetEc2LiveTest.java | 3 +- .../mongodb/MongoDBRestartIntegrationTest.java | 5 +- .../nosql/mongodb/MongoDBSoftLayerLiveTest.java | 3 +- .../MongoDBShardedDeploymentEc2LiveTest.java | 3 +- .../entity/nosql/redis/RedisEc2LiveTest.java | 3 +- .../nosql/riak/RiakClusterEc2LiveTest.java | 3 +- .../entity/nosql/riak/RiakNodeEc2LiveTest.java | 3 +- .../riak/RiakNodeGoogleComputeLiveTest.java | 3 +- .../nosql/riak/RiakNodeSoftlayerLiveTest.java | 3 +- .../nosql/solr/SolrServerEc2LiveTest.java | 3 +- .../entity/osgi/karaf/KarafContainer.java | 7 +- .../entity/osgi/karaf/KarafContainerImpl.java | 13 +- .../brooklyn/entity/osgi/karaf/KarafDriver.java | 2 +- .../entity/osgi/karaf/KarafSshDriver.java | 3 +- .../osgi/karaf/KarafContainerEc2LiveTest.java | 3 +- .../entity/osgi/karaf/KarafContainerTest.java | 4 +- .../entity/proxy/AbstractController.java | 3 +- .../entity/proxy/AbstractControllerImpl.java | 4 +- .../entity/proxy/nginx/NginxController.java | 3 +- .../entity/proxy/nginx/NginxDriver.java | 2 +- .../entity/proxy/nginx/NginxSshDriver.java | 6 +- .../entity/webapp/JavaWebAppDriver.java | 2 +- .../entity/webapp/JavaWebAppService.java | 3 +- .../webapp/JavaWebAppSoftwareProcess.java | 2 +- .../webapp/JavaWebAppSoftwareProcessImpl.java | 5 +- .../entity/webapp/JavaWebAppSshDriver.java | 3 +- .../entity/webapp/jboss/JBoss6Server.java | 5 +- .../entity/webapp/jboss/JBoss6ServerImpl.java | 5 +- .../entity/webapp/jboss/JBoss6SshDriver.java | 6 +- .../entity/webapp/jboss/JBoss7Server.java | 3 +- .../entity/webapp/jboss/JBoss7SshDriver.java | 4 +- .../entity/webapp/jetty/Jetty6Server.java | 5 +- .../entity/webapp/jetty/Jetty6ServerImpl.java | 9 +- .../webapp/nodejs/NodeJsWebAppDriver.java | 2 +- .../webapp/nodejs/NodeJsWebAppService.java | 4 +- .../webapp/nodejs/NodeJsWebAppServiceImpl.java | 4 +- .../webapp/nodejs/NodeJsWebAppSshDriver.java | 6 +- .../entity/webapp/tomcat/Tomcat8Server.java | 3 +- .../entity/webapp/tomcat/TomcatServer.java | 6 +- .../entity/webapp/tomcat/TomcatServerImpl.java | 7 +- .../proxy/TrackingAbstractControllerImpl.java | 3 +- .../entity/proxy/nginx/NginxEc2LiveTest.java | 5 +- .../nginx/NginxHttpsSslIntegrationTest.java | 4 +- .../proxy/nginx/NginxIntegrationTest.java | 3 +- .../proxy/nginx/NginxRebindIntegrationTest.java | 4 +- .../AbstractWebAppFixtureIntegrationTest.java | 7 +- .../ControlledDynamicWebAppClusterTest.java | 4 +- ...namicWebAppClusterRebindIntegrationTest.java | 4 +- .../jboss/JBoss6ServerAwsEc2LiveTest.java | 3 +- ...Boss6ServerNonInheritingIntegrationTest.java | 4 +- .../jboss/JBoss7ServerAwsEc2LiveTest.java | 3 +- .../jboss/JBoss7ServerDockerLiveTest.java | 3 +- .../JBoss7ServerRebindingIntegrationTest.java | 4 +- ...ultiVersionWebAppFixtureIntegrationTest.java | 4 +- .../Jboss7ServerGoogleComputeLiveTest.java | 3 +- .../JettyWebAppFixtureIntegrationTest.java | 4 +- .../webapp/nodejs/NodeJsWebAppEc2LiveTest.java | 3 +- .../NodeJsWebAppFixtureIntegrationTest.java | 3 +- .../nodejs/NodeJsWebAppSoftlayerLiveTest.java | 3 +- .../webapp/tomcat/Tomcat8ServerEc2LiveTest.java | 4 +- .../Tomcat8ServerRestartIntegrationTest.java | 5 +- .../tomcat/Tomcat8ServerSoftlayerLiveTest.java | 4 +- ...mcat8ServerWebAppFixtureIntegrationTest.java | 4 +- ...ableRetrieveUsageMetricsIntegrationTest.java | 4 +- .../webapp/tomcat/TomcatServerEc2LiveTest.java | 3 +- .../TomcatServerRestartIntegrationTest.java | 5 +- .../tomcat/TomcatServerSoftlayerLiveTest.java | 3 +- ...omcatServerWebAppFixtureIntegrationTest.java | 4 +- .../test/entity/TestJavaWebAppEntity.java | 7 +- .../test/entity/TestJavaWebAppEntityImpl.java | 3 +- .../service/CatalogServiceTypeResolver.java | 7 +- .../service/ChefServiceTypeResolver.java | 5 +- .../camp/brooklyn/ByonLocationsYamlTest.java | 3 +- .../brooklyn/EmptySoftwareProcessYamlTest.java | 4 +- .../camp/brooklyn/EntitiesYamlTest.java | 3 +- .../test/resources/same-server-entity-test.yaml | 2 +- .../apache/brooklyn/cli/lister/ClassFinder.java | 3 +- .../main/webapp/assets/js/view/script-groovy.js | 2 +- .../specs/model/catalog-application-spec.js | 8 +- .../specs/model/sensor-summary-spec.js | 2 +- .../brooklyn/launcher/BrooklynLauncher.java | 7 +- .../entity/basic/VanillaSoftwareYamlTest.java | 4 +- .../BrooklynEntityMirrorIntegrationTest.java | 4 +- .../brooklynnode/BrooklynNodeRestTest.java | 9 +- .../blueprints/AbstractBlueprintTest.java | 4 +- .../qa/load/SimulatedMySqlNodeImpl.java | 5 +- .../brooklyn/qa/load/SimulatedTheeTierApp.java | 3 +- .../SoftlayerObtainPrivateLiveTest.java | 7 +- .../src/main/resources/reset-catalog.xml | 2 +- .../rest/resources/ServerResourceTest.java | 7 +- .../rest/resources/UsageResourceTest.java | 4 +- .../brooklynnode/DeployBlueprintTest.java | 5 +- .../testing/mocks/RestMockSimpleEntity.java | 6 +- .../rest/util/EntityLocationUtilsTest.java | 4 +- 628 files changed, 28689 insertions(+), 29041 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/core/src/main/java/org/apache/brooklyn/sensor/core/HttpRequestSensor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/sensor/core/HttpRequestSensor.java b/core/src/main/java/org/apache/brooklyn/sensor/core/HttpRequestSensor.java new file mode 100644 index 0000000..2277d49 --- /dev/null +++ b/core/src/main/java/org/apache/brooklyn/sensor/core/HttpRequestSensor.java @@ -0,0 +1,99 @@ +/* + * 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.sensor.core; + +import java.net.URI; + +import net.minidev.json.JSONObject; + +import org.apache.brooklyn.api.internal.EntityLocal; +import org.apache.brooklyn.config.ConfigKey; +import org.apache.brooklyn.core.config.ConfigKeys; +import org.apache.brooklyn.effector.core.AddSensor; +import org.apache.brooklyn.entity.java.JmxAttributeSensor; +import org.apache.brooklyn.entity.software.ssh.SshCommandSensor; +import org.apache.brooklyn.sensor.core.HttpRequestSensor; +import org.apache.brooklyn.sensor.feed.http.HttpFeed; +import org.apache.brooklyn.sensor.feed.http.HttpPollConfig; +import org.apache.brooklyn.sensor.feed.http.HttpValueFunctions; +import org.apache.brooklyn.util.core.config.ConfigBag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.annotations.Beta; +import com.google.common.base.Functions; +import com.google.common.base.Supplier; + +/** + * Configurable {@link org.apache.brooklyn.api.entity.EntityInitializer} which adds an HTTP sensor feed to retrieve the + * {@link JSONObject} from a JSON response in order to populate the sensor with the data at the {@code jsonPath}. + * + * @see SshCommandSensor + * @see JmxAttributeSensor + */ +@Beta +public final class HttpRequestSensor<T> extends AddSensor<T> { + + private static final Logger LOG = LoggerFactory.getLogger(HttpRequestSensor.class); + + public static final ConfigKey<String> SENSOR_URI = ConfigKeys.newStringConfigKey("uri", "HTTP URI to poll for JSON"); + public static final ConfigKey<String> JSON_PATH = ConfigKeys.newStringConfigKey("jsonPath", "JSON path to select in HTTP response; default $", "$"); + public static final ConfigKey<String> USERNAME = ConfigKeys.newStringConfigKey("username", "Username for HTTP request, if required"); + public static final ConfigKey<String> PASSWORD = ConfigKeys.newStringConfigKey("password", "Password for HTTP request, if required"); + + protected final Supplier<URI> uri; + protected final String jsonPath; + protected final String username; + protected final String password; + + public HttpRequestSensor(final ConfigBag params) { + super(params); + + uri = new Supplier<URI>() { + @Override + public URI get() { + return URI.create(params.get(SENSOR_URI)); + } + }; + jsonPath = params.get(JSON_PATH); + username = params.get(USERNAME); + password = params.get(PASSWORD); + } + + @Override + public void apply(final EntityLocal entity) { + super.apply(entity); + + if (LOG.isDebugEnabled()) { + LOG.debug("Adding HTTP JSON sensor {} to {}", name, entity); + } + + HttpPollConfig<T> pollConfig = new HttpPollConfig<T>(sensor) + .checkSuccess(HttpValueFunctions.responseCodeEquals(200)) + .onFailureOrException(Functions.constant((T) null)) + .onSuccess(HttpValueFunctions.<T>jsonContentsFromPath(jsonPath)) + .period(period); + + HttpFeed.builder().entity(entity) + .baseUri(uri) + .credentialsIfNotNull(username, password) + .poll(pollConfig) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/core/src/main/java/org/apache/brooklyn/sensor/core/StaticSensor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/sensor/core/StaticSensor.java b/core/src/main/java/org/apache/brooklyn/sensor/core/StaticSensor.java new file mode 100644 index 0000000..29e679d --- /dev/null +++ b/core/src/main/java/org/apache/brooklyn/sensor/core/StaticSensor.java @@ -0,0 +1,72 @@ +/* + * 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.sensor.core; + +import org.apache.brooklyn.api.internal.EntityLocal; +import org.apache.brooklyn.api.mgmt.Task; +import org.apache.brooklyn.config.ConfigKey; +import org.apache.brooklyn.core.config.ConfigKeys; +import org.apache.brooklyn.effector.core.AddSensor; +import org.apache.brooklyn.sensor.enricher.Propagator; +import org.apache.brooklyn.util.core.config.ConfigBag; +import org.apache.brooklyn.util.core.task.Tasks; +import org.apache.brooklyn.util.core.task.ValueResolver; +import org.apache.brooklyn.util.guava.Maybe; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Supplier; + +/** + * Provides an initializer/feed which simply sets a given value. + * <p> + * {@link Task}/{@link Supplier} values are resolved when written, + * unlike config values which are resolved on each read. + * <p> + * This supports a {@link StaticSensor#SENSOR_PERIOD} + * which can be useful if the supplied value is such a function. + * However when the source is another sensor, + * consider using {@link Propagator} which listens for changes instead. */ +public class StaticSensor<T> extends AddSensor<T> { + + private static final Logger log = LoggerFactory.getLogger(StaticSensor.class); + + public static final ConfigKey<Object> STATIC_VALUE = ConfigKeys.newConfigKey(Object.class, "static.value"); + + private final Object value; + + public StaticSensor(ConfigBag params) { + super(params); + value = params.get(STATIC_VALUE); + } + + @SuppressWarnings("unchecked") + @Override + public void apply(EntityLocal entity) { + super.apply(entity); + + Maybe<T> v = Tasks.resolving(value).as((Class<T>)sensor.getType()).timeout(ValueResolver.PRETTY_QUICK_WAIT).getMaybe(); + if (v.isPresent()) { + log.debug(this+" setting sensor "+sensor+" to "+v.get()); + entity.setAttribute(sensor, v.get()); + } else { + log.debug(this+" not setting sensor "+sensor+"; cannot resolve "+value); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/core/src/test/java/org/apache/brooklyn/sensor/core/HttpRequestSensorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/sensor/core/HttpRequestSensorTest.java b/core/src/test/java/org/apache/brooklyn/sensor/core/HttpRequestSensorTest.java new file mode 100644 index 0000000..91120e6 --- /dev/null +++ b/core/src/test/java/org/apache/brooklyn/sensor/core/HttpRequestSensorTest.java @@ -0,0 +1,85 @@ +/* + * 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.sensor.core; + +import org.apache.brooklyn.api.entity.EntitySpec; +import org.apache.brooklyn.api.internal.EntityLocal; +import org.apache.brooklyn.api.location.Location; +import org.apache.brooklyn.api.sensor.AttributeSensor; +import org.apache.brooklyn.core.test.TestHttpRequestHandler; +import org.apache.brooklyn.core.test.TestHttpServer; +import org.apache.brooklyn.core.test.entity.TestApplication; +import org.apache.brooklyn.core.test.entity.TestEntity; +import org.apache.brooklyn.entity.core.Attributes; +import org.apache.brooklyn.entity.core.Entities; +import org.apache.brooklyn.sensor.core.HttpRequestSensor; +import org.apache.brooklyn.sensor.core.Sensors; +import org.apache.brooklyn.test.EntityTestUtils; +import org.apache.brooklyn.util.core.config.ConfigBag; +import org.apache.brooklyn.util.time.Duration; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +public class HttpRequestSensorTest { + final static AttributeSensor<String> SENSOR_STRING = Sensors.newStringSensor("aString"); + final static String TARGET_TYPE = "java.lang.String"; + + private TestApplication app; + private EntityLocal entity; + + private TestHttpServer server; + private String serverUrl; + + @BeforeClass(alwaysRun=true) + public void setUp() throws Exception { + server = new TestHttpServer() + .handler("/myKey/myValue", new TestHttpRequestHandler().header("Content-Type", "application/json").response("{\"myKey\":\"myValue\"}")) + .start(); + serverUrl = server.getUrl(); + + app = TestApplication.Factory.newManagedInstanceForTests(); + entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) + .location(app.newLocalhostProvisioningLocation().obtain())); + app.start(ImmutableList.<Location>of()); + } + + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + if (app != null) Entities.destroyAll(app.getManagementContext()); + server.stop(); + } + + @Test + public void testHttpSensor() throws Exception { + HttpRequestSensor<Integer> sensor = new HttpRequestSensor<Integer>(ConfigBag.newInstance() + .configure(HttpRequestSensor.SENSOR_PERIOD, Duration.millis(100)) + .configure(HttpRequestSensor.SENSOR_NAME, SENSOR_STRING.getName()) + .configure(HttpRequestSensor.SENSOR_TYPE, TARGET_TYPE) + .configure(HttpRequestSensor.JSON_PATH, "$.myKey") + .configure(HttpRequestSensor.SENSOR_URI, serverUrl + "/myKey/myValue")); + sensor.apply(entity); + entity.setAttribute(Attributes.SERVICE_UP, true); + + EntityTestUtils.assertAttributeEqualsEventually(entity, SENSOR_STRING, "myValue"); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/core/src/test/java/org/apache/brooklyn/sensor/core/StaticSensorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/sensor/core/StaticSensorTest.java b/core/src/test/java/org/apache/brooklyn/sensor/core/StaticSensorTest.java new file mode 100644 index 0000000..a62d985 --- /dev/null +++ b/core/src/test/java/org/apache/brooklyn/sensor/core/StaticSensorTest.java @@ -0,0 +1,55 @@ +/* + * 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.sensor.core; + +import org.apache.brooklyn.api.entity.EntitySpec; +import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; +import org.apache.brooklyn.entity.stock.BasicEntity; +import org.apache.brooklyn.sensor.core.Sensors; +import org.apache.brooklyn.sensor.core.StaticSensor; +import org.apache.brooklyn.test.EntityTestUtils; +import org.apache.brooklyn.util.core.config.ConfigBag; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; + +public class StaticSensorTest extends BrooklynAppUnitTestSupport { + + @Test + public void testAddsStaticSensorOfTypeString() { + BasicEntity entity = app.createAndManageChild(EntitySpec.create(BasicEntity.class) + .addInitializer(new StaticSensor<String>(ConfigBag.newInstance(ImmutableMap.of( + StaticSensor.SENSOR_NAME, "myname", + StaticSensor.SENSOR_TYPE, String.class.getName(), + StaticSensor.STATIC_VALUE, "myval"))))); + + EntityTestUtils.assertAttributeEquals(entity, Sensors.newSensor(String.class, "myname"), "myval"); + } + + @Test + public void testAddsStaticSensorOfTypeInteger() { + BasicEntity entity = app.createAndManageChild(EntitySpec.create(BasicEntity.class) + .addInitializer(new StaticSensor<Integer>(ConfigBag.newInstance(ImmutableMap.of( + StaticSensor.SENSOR_NAME, "myname", + StaticSensor.SENSOR_TYPE, Integer.class.getName(), + StaticSensor.STATIC_VALUE, "1"))))); + + EntityTestUtils.assertAttributeEquals(entity, Sensors.newSensor(Integer.class, "myname"), 1); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/examples/simple-nosql-cluster/src/main/java/org/apache/brooklyn/demo/CumulusRDFApplication.java ---------------------------------------------------------------------- diff --git a/examples/simple-nosql-cluster/src/main/java/org/apache/brooklyn/demo/CumulusRDFApplication.java b/examples/simple-nosql-cluster/src/main/java/org/apache/brooklyn/demo/CumulusRDFApplication.java index bcdd143..26891d5 100644 --- a/examples/simple-nosql-cluster/src/main/java/org/apache/brooklyn/demo/CumulusRDFApplication.java +++ b/examples/simple-nosql-cluster/src/main/java/org/apache/brooklyn/demo/CumulusRDFApplication.java @@ -42,6 +42,8 @@ import org.apache.brooklyn.entity.core.AbstractApplication; import org.apache.brooklyn.entity.core.Entities; import org.apache.brooklyn.entity.core.EntityInternal; import org.apache.brooklyn.entity.core.StartableApplication; +import org.apache.brooklyn.entity.java.UsesJava; +import org.apache.brooklyn.entity.java.UsesJmx; import org.apache.brooklyn.entity.lifecycle.Lifecycle; import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic; import org.apache.brooklyn.entity.nosql.cassandra.CassandraDatacenter; @@ -50,17 +52,13 @@ import org.apache.brooklyn.entity.nosql.cassandra.CassandraNode; import org.apache.brooklyn.entity.trait.Startable; import org.apache.brooklyn.entity.webapp.JavaWebAppService; import org.apache.brooklyn.entity.webapp.tomcat.TomcatServer; - -import brooklyn.entity.java.UsesJava; -import brooklyn.entity.java.UsesJmx; -import brooklyn.entity.software.SshEffectorTasks; - import org.apache.brooklyn.launcher.BrooklynLauncher; import org.apache.brooklyn.location.basic.PortRanges; import org.apache.brooklyn.policy.ha.ServiceFailureDetector; import org.apache.brooklyn.policy.ha.ServiceReplacer; import org.apache.brooklyn.policy.ha.ServiceRestarter; import org.apache.brooklyn.sensor.core.DependentConfiguration; +import org.apache.brooklyn.sensor.ssh.SshEffectorTasks; import org.apache.brooklyn.util.CommandLineUtil; import org.apache.brooklyn.util.collections.MutableList; import org.apache.brooklyn.util.collections.MutableMap; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/examples/simple-nosql-cluster/src/main/java/org/apache/brooklyn/demo/ResilientMongoDbApp.java ---------------------------------------------------------------------- diff --git a/examples/simple-nosql-cluster/src/main/java/org/apache/brooklyn/demo/ResilientMongoDbApp.java b/examples/simple-nosql-cluster/src/main/java/org/apache/brooklyn/demo/ResilientMongoDbApp.java index ab70e77..fdce4d0 100644 --- a/examples/simple-nosql-cluster/src/main/java/org/apache/brooklyn/demo/ResilientMongoDbApp.java +++ b/examples/simple-nosql-cluster/src/main/java/org/apache/brooklyn/demo/ResilientMongoDbApp.java @@ -33,9 +33,7 @@ import org.apache.brooklyn.entity.core.StartableApplication; import org.apache.brooklyn.entity.group.DynamicCluster; import org.apache.brooklyn.entity.nosql.mongodb.MongoDBReplicaSet; import org.apache.brooklyn.entity.nosql.mongodb.MongoDBServer; - -import brooklyn.entity.basic.SoftwareProcess; - +import org.apache.brooklyn.entity.software.base.SoftwareProcess; import org.apache.brooklyn.launcher.BrooklynLauncher; import org.apache.brooklyn.policy.ha.ServiceFailureDetector; import org.apache.brooklyn.policy.ha.ServiceReplacer; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/NodeJsTodoApplication.java ---------------------------------------------------------------------- diff --git a/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/NodeJsTodoApplication.java b/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/NodeJsTodoApplication.java index fd3a22c..eed6a05 100644 --- a/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/NodeJsTodoApplication.java +++ b/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/NodeJsTodoApplication.java @@ -26,12 +26,11 @@ import org.apache.brooklyn.entity.core.AbstractApplication; import org.apache.brooklyn.entity.core.Attributes; import org.apache.brooklyn.entity.core.StartableApplication; import org.apache.brooklyn.entity.nosql.redis.RedisStore; +import org.apache.brooklyn.entity.software.base.SoftwareProcess; import org.apache.brooklyn.entity.trait.Startable; import org.apache.brooklyn.entity.webapp.nodejs.NodeJsWebAppService; import org.apache.brooklyn.sensor.core.DependentConfiguration; -import brooklyn.entity.basic.SoftwareProcess; - import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/WebClusterDatabaseExample.java ---------------------------------------------------------------------- diff --git a/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/WebClusterDatabaseExample.java b/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/WebClusterDatabaseExample.java index a22a8a6..8682335 100644 --- a/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/WebClusterDatabaseExample.java +++ b/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/WebClusterDatabaseExample.java @@ -18,7 +18,7 @@ */ package org.apache.brooklyn.demo; -import static brooklyn.entity.java.JavaEntityMethods.javaSysProp; +import static org.apache.brooklyn.entity.java.JavaEntityMethods.javaSysProp; import static org.apache.brooklyn.sensor.core.DependentConfiguration.attributeWhenReady; import static org.apache.brooklyn.sensor.core.DependentConfiguration.formatString; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/WebClusterDatabaseExampleApp.java ---------------------------------------------------------------------- diff --git a/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/WebClusterDatabaseExampleApp.java b/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/WebClusterDatabaseExampleApp.java index a988440..e13a632 100644 --- a/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/WebClusterDatabaseExampleApp.java +++ b/examples/simple-web-cluster/src/main/java/org/apache/brooklyn/demo/WebClusterDatabaseExampleApp.java @@ -42,9 +42,7 @@ import org.apache.brooklyn.entity.core.Entities; import org.apache.brooklyn.entity.core.StartableApplication; import org.apache.brooklyn.entity.database.mysql.MySqlNode; import org.apache.brooklyn.entity.group.DynamicCluster; - -import brooklyn.entity.java.JavaEntityMethods; - +import org.apache.brooklyn.entity.java.JavaEntityMethods; import org.apache.brooklyn.launcher.BrooklynLauncher; import org.apache.brooklyn.location.basic.PortRanges; import org.apache.brooklyn.policy.autoscaling.AutoScalerPolicy; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/examples/simple-web-cluster/src/test/java/org/apache/brooklyn/demo/RebindWebClusterDatabaseExampleAppIntegrationTest.java ---------------------------------------------------------------------- diff --git a/examples/simple-web-cluster/src/test/java/org/apache/brooklyn/demo/RebindWebClusterDatabaseExampleAppIntegrationTest.java b/examples/simple-web-cluster/src/test/java/org/apache/brooklyn/demo/RebindWebClusterDatabaseExampleAppIntegrationTest.java index c302141..fabb071 100644 --- a/examples/simple-web-cluster/src/test/java/org/apache/brooklyn/demo/RebindWebClusterDatabaseExampleAppIntegrationTest.java +++ b/examples/simple-web-cluster/src/test/java/org/apache/brooklyn/demo/RebindWebClusterDatabaseExampleAppIntegrationTest.java @@ -56,9 +56,7 @@ import org.apache.brooklyn.entity.core.Entities; import org.apache.brooklyn.entity.core.StartableApplication; import org.apache.brooklyn.entity.database.mysql.MySqlNode; import org.apache.brooklyn.entity.group.DynamicCluster; - -import brooklyn.entity.java.JavaEntityMethods; - +import org.apache.brooklyn.entity.java.JavaEntityMethods; import org.apache.brooklyn.policy.autoscaling.AutoScalerPolicy; import org.apache.brooklyn.policy.enricher.HttpLatencyDetector; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/64c2b2e5/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java deleted file mode 100644 index 0b145a4..0000000 --- a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java +++ /dev/null @@ -1,516 +0,0 @@ -/* - * 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 brooklyn.entity.basic; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.apache.brooklyn.util.JavaGroovyEquivalents.elvis; - -import java.io.File; -import java.io.InputStream; -import java.io.Reader; -import java.io.StringReader; -import java.util.Map; - -import org.apache.brooklyn.api.internal.EntityLocal; -import org.apache.brooklyn.api.location.Location; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.entity.core.BrooklynConfigKeys; -import org.apache.brooklyn.entity.lifecycle.Lifecycle; -import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.core.ResourceUtils; -import org.apache.brooklyn.util.core.task.DynamicTasks; -import org.apache.brooklyn.util.core.task.Tasks; -import org.apache.brooklyn.util.core.text.TemplateProcessor; -import org.apache.brooklyn.util.exceptions.Exceptions; -import org.apache.brooklyn.util.os.Os; -import org.apache.brooklyn.util.stream.ReaderInputStream; -import org.apache.brooklyn.util.text.Strings; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.annotations.Beta; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableMap; - -/** - * An abstract implementation of the {@link SoftwareProcessDriver}. - */ -public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDriver { - - private static final Logger log = LoggerFactory.getLogger(AbstractSoftwareProcessDriver.class); - - protected final EntityLocal entity; - protected final ResourceUtils resource; - protected final Location location; - - public AbstractSoftwareProcessDriver(EntityLocal entity, Location location) { - this.entity = checkNotNull(entity, "entity"); - this.location = checkNotNull(location, "location"); - this.resource = ResourceUtils.create(entity); - } - - /* - * (non-Javadoc) - * @see brooklyn.entity.basic.SoftwareProcessDriver#rebind() - */ - @Override - public void rebind() { - // no-op - } - - /** - * Start the entity. - * <p> - * This installs, configures and launches the application process. However, - * users can also call the {@link #install()}, {@link #customize()} and - * {@link #launch()} steps independently. The {@link #postLaunch()} will - * be called after the {@link #launch()} metheod is executed, but the - * process may not be completely initialised at this stage, so care is - * required when implementing these stages. - * <p> - * The {@link BrooklynConfigKeys#ENTITY_RUNNING} key can be set on the location - * or the entity to skip the startup process if the entity is already running, - * according to the {@link #isRunning()} method. To force the startup to be - * skipped, {@link BrooklynConfigKeys#SKIP_ENTITY_START} can be set on the entity. - * The {@link BrooklynConfigKeys#SKIP_ENTITY_INSTALLATION} key can also be used to - * skip the {@link #setup()}, {@link #copyInstallResources()} and - * {@link #install()} methods if set on the entity or location. - * - * @see #stop() - */ - @Override - public void start() { - boolean skipStart = false; - Optional<Boolean> locationRunning = Optional.fromNullable(getLocation().getConfig(BrooklynConfigKeys.SKIP_ENTITY_START_IF_RUNNING)); - Optional<Boolean> entityRunning = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_ENTITY_START_IF_RUNNING)); - Optional<Boolean> entityStarted = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_ENTITY_START)); - if (locationRunning.or(entityRunning).or(false)) { - skipStart = isRunning(); - } else { - skipStart = entityStarted.or(false); - } - if (!skipStart) { - DynamicTasks.queue("copy-pre-install-resources", new Runnable() { public void run() { - waitForConfigKey(BrooklynConfigKeys.PRE_INSTALL_RESOURCES_LATCH); - copyPreInstallResources(); - }}); - - DynamicTasks.queue("pre-install", new Runnable() { public void run() { - preInstall(); - }}); - - if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.PRE_INSTALL_COMMAND))) { - DynamicTasks.queue("pre-install-command", new Runnable() { public void run() { - runPreInstallCommand(entity.getConfig(BrooklynConfigKeys.PRE_INSTALL_COMMAND)); - }}); - }; - - Optional<Boolean> locationInstalled = Optional.fromNullable(getLocation().getConfig(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION)); - Optional<Boolean> entityInstalled = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION)); - boolean skipInstall = locationInstalled.or(entityInstalled).or(false); - if (!skipInstall) { - DynamicTasks.queue("setup", new Runnable() { public void run() { - waitForConfigKey(BrooklynConfigKeys.SETUP_LATCH); - setup(); - }}); - - DynamicTasks.queue("copy-install-resources", new Runnable() { public void run() { - waitForConfigKey(BrooklynConfigKeys.INSTALL_RESOURCES_LATCH); - copyInstallResources(); - }}); - - DynamicTasks.queue("install", new Runnable() { public void run() { - waitForConfigKey(BrooklynConfigKeys.INSTALL_LATCH); - install(); - }}); - } - - if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.POST_INSTALL_COMMAND))) { - DynamicTasks.queue("post-install-command", new Runnable() { public void run() { - runPostInstallCommand(entity.getConfig(BrooklynConfigKeys.POST_INSTALL_COMMAND)); - }}); - } - - DynamicTasks.queue("customize", new Runnable() { public void run() { - waitForConfigKey(BrooklynConfigKeys.CUSTOMIZE_LATCH); - customize(); - }}); - - DynamicTasks.queue("copy-runtime-resources", new Runnable() { public void run() { - waitForConfigKey(BrooklynConfigKeys.RUNTIME_RESOURCES_LATCH); - copyRuntimeResources(); - }}); - - if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.PRE_LAUNCH_COMMAND))) { - DynamicTasks.queue("pre-launch-command", new Runnable() { public void run() { - runPreLaunchCommand(entity.getConfig(BrooklynConfigKeys.PRE_LAUNCH_COMMAND)); - }}); - }; - - DynamicTasks.queue("launch", new Runnable() { public void run() { - waitForConfigKey(BrooklynConfigKeys.LAUNCH_LATCH); - launch(); - }}); - - if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.POST_LAUNCH_COMMAND))) { - DynamicTasks.queue("post-launch-command", new Runnable() { public void run() { - runPostLaunchCommand(entity.getConfig(BrooklynConfigKeys.POST_LAUNCH_COMMAND)); - }}); - }; - } - - DynamicTasks.queue("post-launch", new Runnable() { public void run() { - postLaunch(); - }}); - } - - @Override - public abstract void stop(); - - /** - * Implement this method in child classes to add some pre-install behavior - */ - public void preInstall() {} - - public abstract void runPreInstallCommand(String command); - public abstract void setup(); - public abstract void install(); - public abstract void runPostInstallCommand(String command); - public abstract void customize(); - public abstract void runPreLaunchCommand(String command); - public abstract void launch(); - public abstract void runPostLaunchCommand(String command); - - @Override - public void kill() { - stop(); - } - - /** - * Implement this method in child classes to add some post-launch behavior - */ - public void postLaunch() {} - - @Override - public void restart() { - DynamicTasks.queue("stop (best effort)", new Runnable() { - public void run() { - DynamicTasks.markInessential(); - boolean previouslyRunning = isRunning(); - try { - ServiceStateLogic.setExpectedState(getEntity(), Lifecycle.STOPPING); - stop(); - } catch (Exception e) { - // queue a failed task so that there is visual indication that this task had a failure, - // without interrupting the parent - if (previouslyRunning) { - log.warn(getEntity() + " restart: stop failed, when was previously running (ignoring)", e); - DynamicTasks.queue(Tasks.fail("Primary job failure (when previously running)", e)); - } else { - log.debug(getEntity() + " restart: stop failed (but was not previously running, so not a surprise)", e); - DynamicTasks.queue(Tasks.fail("Primary job failure (when not previously running)", e)); - } - // the above queued tasks will cause this task to be indicated as failed, with an indication of severity - } - } - }); - - if (doFullStartOnRestart()) { - DynamicTasks.waitForLast(); - ServiceStateLogic.setExpectedState(getEntity(), Lifecycle.STARTING); - start(); - } else { - DynamicTasks.queue("launch", new Runnable() { public void run() { - ServiceStateLogic.setExpectedState(getEntity(), Lifecycle.STARTING); - launch(); - }}); - DynamicTasks.queue("post-launch", new Runnable() { public void run() { - postLaunch(); - }}); - } - } - - @Beta - /** ideally restart() would take options, e.g. whether to do full start, skip installs, etc; - * however in the absence here is a toggle - not sure how well it works; - * default is false which is similar to previous behaviour (with some seemingly-obvious tidies), - * meaning install and configure will NOT be done on restart. */ - protected boolean doFullStartOnRestart() { - return false; - } - - @Override - public EntityLocal getEntity() { return entity; } - - @Override - public Location getLocation() { return location; } - - public InputStream getResource(String url) { - return resource.getResourceFromUrl(url); - } - - /** - * Files and templates to be copied to the server <em>before</em> pre-install. This allows the {@link #preInstall()} - * process to have access to all required resources. - * <p> - * Will be prefixed with the entity's {@link #getInstallDir() install directory} if relative. - * - * @see SoftwareProcess#PRE_INSTALL_FILES - * @see SoftwareProcess#PRE_INSTALL_TEMPLATES - * @see #copyRuntimeResources() - */ - public void copyPreInstallResources() { - copyResources(entity.getConfig(SoftwareProcess.PRE_INSTALL_FILES), entity.getConfig(SoftwareProcess.PRE_INSTALL_TEMPLATES)); - } - - /** - * Files and templates to be copied to the server <em>before</em> installation. This allows the {@link #install()} - * process to have access to all required resources. - * <p> - * Will be prefixed with the entity's {@link #getInstallDir() install directory} if relative. - * - * @see SoftwareProcess#INSTALL_FILES - * @see SoftwareProcess#INSTALL_TEMPLATES - * @see #copyRuntimeResources() - */ - public void copyInstallResources() { - copyResources(entity.getConfig(SoftwareProcess.INSTALL_FILES), entity.getConfig(SoftwareProcess.INSTALL_TEMPLATES)); - } - - private void copyResources(Map<String, String> files, Map<String, String> templates) { - // Ensure environment variables are not looked up here, otherwise sub-classes might - // lookup port numbers and fail with ugly error if port is not set; better to wait - // until in Entity's code (e.g. customize) where such checks are done explicitly. - - boolean hasAnythingToCopy = ((files != null && files.size() > 0) || (templates != null && templates.size() > 0)); - if (hasAnythingToCopy) { - createDirectory(getInstallDir(), "create install directory"); - - // TODO see comment in copyResource, that should be queued as a task like the above - // (better reporting in activities console) - - if (files != null && files.size() > 0) { - for (String source : files.keySet()) { - String target = files.get(source); - String destination = Os.isAbsolutish(target) ? target : Os.mergePathsUnix(getInstallDir(), target); - copyResource(source, destination, true); - } - } - - if (templates != null && templates.size() > 0) { - for (String source : templates.keySet()) { - String target = templates.get(source); - String destination = Os.isAbsolutish(target) ? target : Os.mergePathsUnix(getInstallDir(), target); - copyTemplate(source, destination, true, MutableMap.<String, Object>of()); - } - } - } - } - - protected abstract void createDirectory(String directoryName, String summaryForLogging); - - /** - * Files and templates to be copied to the server <em>after</em> customisation. This allows overwriting of - * existing files such as entity configuration which may be copied from the installation directory - * during the {@link #customize()} process. - * <p> - * Will be prefixed with the entity's {@link #getRunDir() run directory} if relative. - * - * @see SoftwareProcess#RUNTIME_FILES - * @see SoftwareProcess#RUNTIME_TEMPLATES - * @see #copyInstallResources() - */ - public void copyRuntimeResources() { - try { - createDirectory(getRunDir(), "create run directory"); - - Map<String, String> runtimeFiles = entity.getConfig(SoftwareProcess.RUNTIME_FILES); - if (runtimeFiles != null && runtimeFiles.size() > 0) { - for (String source : runtimeFiles.keySet()) { - String target = runtimeFiles.get(source); - String destination = Os.isAbsolutish(target) ? target : Os.mergePathsUnix(getRunDir(), target); - copyResource(source, destination, true); - } - } - - Map<String, String> runtimeTemplates = entity.getConfig(SoftwareProcess.RUNTIME_TEMPLATES); - if (runtimeTemplates != null && runtimeTemplates.size() > 0) { - for (String source : runtimeTemplates.keySet()) { - String target = runtimeTemplates.get(source); - String destination = Os.isAbsolutish(target) ? target : Os.mergePathsUnix(getRunDir(), target); - copyTemplate(source, destination, true, MutableMap.<String, Object>of()); - } - } - } catch (Exception e) { - log.warn("Error copying runtime resources", e); - throw Exceptions.propagate(e); - } - } - - /** - * @param template File to template and copy. - * @param target Destination on server. - * @return The exit code the SSH command run. - */ - public int copyTemplate(File template, String target) { - return copyTemplate(template.toURI().toASCIIString(), target); - } - - /** - * @param template URI of file to template and copy, e.g. file://.., http://.., classpath://.. - * @param target Destination on server. - * @return The exit code of the SSH command run. - */ - public int copyTemplate(String template, String target) { - return copyTemplate(template, target, false, ImmutableMap.<String, String>of()); - } - - /** - * @param template URI of file to template and copy, e.g. file://.., http://.., classpath://.. - * @param target Destination on server. - * @param extraSubstitutions Extra substitutions for the templater to use, for example - * "foo" -> "bar", and in a template ${foo}. - * @return The exit code of the SSH command run. - */ - public int copyTemplate(String template, String target, boolean createParent, Map<String, ?> extraSubstitutions) { - String data = processTemplate(template, extraSubstitutions); - return copyResource(MutableMap.<Object,Object>of(), new StringReader(data), target, createParent); - } - - public abstract int copyResource(Map<Object,Object> sshFlags, String source, String target, boolean createParentDir); - - public abstract int copyResource(Map<Object,Object> sshFlags, InputStream source, String target, boolean createParentDir); - - /** - * @param file File to copy. - * @param target Destination on server. - * @return The exit code the SSH command run. - */ - public int copyResource(File file, String target) { - return copyResource(file.toURI().toASCIIString(), target); - } - - /** - * @param resource URI of file to copy, e.g. file://.., http://.., classpath://.. - * @param target Destination on server. - * @return The exit code of the SSH command run - */ - public int copyResource(String resource, String target) { - return copyResource(MutableMap.of(), resource, target); - } - - public int copyResource(String resource, String target, boolean createParentDir) { - return copyResource(MutableMap.of(), resource, target, createParentDir); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public int copyResource(Map sshFlags, String source, String target) { - return copyResource(sshFlags, source, target, false); - } - - /** - * @see #copyResource(Map, InputStream, String, boolean) - */ - public int copyResource(Reader source, String target) { - return copyResource(MutableMap.of(), source, target, false); - } - - /** - * @see #copyResource(Map, InputStream, String, boolean) - */ - public int copyResource(Map<Object,Object> sshFlags, Reader source, String target, boolean createParent) { - return copyResource(sshFlags, new ReaderInputStream(source), target, createParent); - } - - /** - * @see #copyResource(Map, InputStream, String, boolean) - */ - public int copyResource(InputStream source, String target) { - return copyResource(MutableMap.of(), source, target, false); - } - - public String getResourceAsString(String url) { - return resource.getResourceAsString(url); - } - - public String processTemplate(File templateConfigFile, Map<String,Object> extraSubstitutions) { - return processTemplate(templateConfigFile.toURI().toASCIIString(), extraSubstitutions); - } - - public String processTemplate(File templateConfigFile) { - return processTemplate(templateConfigFile.toURI().toASCIIString()); - } - - /** Takes the contents of a template file from the given URL (often a classpath://com/myco/myprod/myfile.conf or .sh) - * and replaces "${entity.xxx}" with the result of entity.getXxx() and similar for other driver, location; - * as well as replacing config keys on the management context - * <p> - * uses Freemarker templates under the covers - **/ - public String processTemplate(String templateConfigUrl) { - return processTemplate(templateConfigUrl, ImmutableMap.<String,String>of()); - } - - public String processTemplate(String templateConfigUrl, Map<String,? extends Object> extraSubstitutions) { - return processTemplateContents(getResourceAsString(templateConfigUrl), extraSubstitutions); - } - - public String processTemplateContents(String templateContents) { - return processTemplateContents(templateContents, ImmutableMap.<String,String>of()); - } - - public String processTemplateContents(String templateContents, Map<String,? extends Object> extraSubstitutions) { - return TemplateProcessor.processTemplateContents(templateContents, this, extraSubstitutions); - } - - protected void waitForConfigKey(ConfigKey<?> configKey) { - Object val = entity.getConfig(configKey); - if (val != null) log.debug("{} finished waiting for {} (value {}); continuing...", new Object[] {this, configKey, val}); - } - - /** - * @deprecated since 0.5.0; instead rely on {@link org.apache.brooklyn.api.entity.drivers.downloads.DownloadResolverManager} to include local-repo, such as: - * - * <pre> - * {@code - * DownloadResolver resolver = Entities.newDownloader(this); - * List<String> urls = resolver.getTargets(); - * } - * </pre> - */ - protected String getEntityVersionLabel() { - return getEntityVersionLabel("_"); - } - - /** - * @deprecated since 0.5.0; instead rely on {@link org.apache.brooklyn.api.entity.drivers.downloads.DownloadResolverManager} to include local-repo - */ - protected String getEntityVersionLabel(String separator) { - return elvis(entity.getEntityType().getSimpleName(), - entity.getClass().getName())+(getVersion() != null ? separator+getVersion() : ""); - } - - public String getVersion() { - return getEntity().getConfig(SoftwareProcess.SUGGESTED_VERSION); - } - - public abstract String getRunDir(); - public abstract String getInstallDir(); -}
