Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Adds EmptyWindowsProcess
- Includes EmptyWindowsProcess.USE_WINRM_MONITORING, for disabling checking of WinRM connectivity. - Adds EmptySoftwareProcess.USE_SSH_MONITORING, for disabling checking of ssh connectivity. With EmptyWindowsProcess, one can provision an entity that will not execute anything on the box. That makes it usable even if there is no direct WinRM connectivity to the box.
- Loading branch information
Showing
8 changed files
with
294 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 org.apache.brooklyn.api.entity.Entity; | ||
import org.apache.brooklyn.core.entity.Attributes; | ||
import org.apache.brooklyn.core.entity.Entities; | ||
import org.apache.brooklyn.core.entity.EntityAsserts; | ||
import org.apache.brooklyn.entity.software.base.EmptyWindowsProcess; | ||
import org.apache.brooklyn.location.winrm.WinRmMachineLocation; | ||
import org.testng.annotations.Test; | ||
|
||
import com.google.common.base.Predicates; | ||
import com.google.common.collect.Iterables; | ||
|
||
@Test | ||
public class EmptyWindowsProcessYamlTest extends AbstractYamlTest { | ||
|
||
@Test(groups="Integration") | ||
public void testNoWinrm() throws Exception { | ||
Entity app = createAndStartApplication( | ||
"location: byon:(hosts=\"1.2.3.4\",osFamily=windows)", | ||
"services:", | ||
"- type: "+EmptyWindowsProcess.class.getName(), | ||
" brooklyn.config:", | ||
" winrmMonitoring.enabled: false"); | ||
waitForApplicationTasks(app); | ||
|
||
EmptyWindowsProcess entity = Iterables.getOnlyElement(Entities.descendants(app, EmptyWindowsProcess.class)); | ||
EntityAsserts.assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, true); | ||
EntityAsserts.assertAttributeEqualsContinually(entity, Attributes.SERVICE_UP, true); | ||
|
||
Iterables.find(entity.getLocations(), Predicates.instanceOf(WinRmMachineLocation.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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.entity.software.base; | ||
|
||
import java.util.Collection; | ||
|
||
import org.apache.brooklyn.api.entity.ImplementedBy; | ||
import org.apache.brooklyn.config.ConfigKey; | ||
import org.apache.brooklyn.core.config.ConfigKeys; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
|
||
@ImplementedBy(EmptyWindowsProcessImpl.class) | ||
public interface EmptyWindowsProcess extends SoftwareProcess { | ||
|
||
// 3389 is RDP; 5985 is WinRM (3389 isn't used by Brooklyn, but useful for the end-user subsequently) | ||
ConfigKey<Collection<Integer>> REQUIRED_OPEN_LOGIN_PORTS = ConfigKeys.newConfigKeyWithDefault( | ||
SoftwareProcess.REQUIRED_OPEN_LOGIN_PORTS, | ||
ImmutableSet.of(5985, 3389)); | ||
|
||
ConfigKey<Boolean> USE_WINRM_MONITORING = ConfigKeys.newConfigKey("winrmMonitoring.enabled", "WinRM monitoring enabled", Boolean.TRUE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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.entity.software.base; | ||
|
||
public interface EmptyWindowsProcessDriver extends SoftwareProcessDriver { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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.entity.software.base; | ||
|
||
import org.apache.brooklyn.core.entity.Attributes; | ||
|
||
public class EmptyWindowsProcessImpl extends SoftwareProcessImpl implements EmptyWindowsProcess { | ||
|
||
@Override | ||
public Class<?> getDriverInterface() { | ||
return EmptyWindowsProcessDriver.class; | ||
} | ||
|
||
@Override | ||
protected void connectSensors() { | ||
super.connectSensors(); | ||
if (isWinrmMonitoringEnabled()) { | ||
connectServiceUpIsRunning(); | ||
} else { | ||
sensors().set(Attributes.SERVICE_UP, true); | ||
} | ||
} | ||
|
||
@Override | ||
protected void disconnectSensors() { | ||
disconnectServiceUpIsRunning(); | ||
super.disconnectSensors(); | ||
} | ||
|
||
protected boolean isWinrmMonitoringEnabled() { | ||
return Boolean.TRUE.equals(getConfig(USE_WINRM_MONITORING)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,97 @@ | ||
/* | ||
* 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.entity.software.base; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import org.apache.brooklyn.core.entity.Attributes; | ||
import org.apache.brooklyn.location.winrm.WinRmMachineLocation; | ||
import org.apache.brooklyn.util.net.UserAndHostAndPort; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class EmptyWindowsProcessWinRmDriver extends AbstractSoftwareProcessWinRmDriver implements VanillaWindowsProcessDriver { | ||
@SuppressWarnings("unused") | ||
private static final Logger LOG = LoggerFactory.getLogger(EmptyWindowsProcessWinRmDriver.class); | ||
|
||
private final AtomicBoolean running = new AtomicBoolean(); | ||
|
||
public EmptyWindowsProcessWinRmDriver(EmptyWindowsProcessImpl entity, WinRmMachineLocation machine) { | ||
super(entity, machine); | ||
} | ||
|
||
@Override | ||
public void start() { | ||
WinRmMachineLocation machine = (WinRmMachineLocation) location; | ||
UserAndHostAndPort winrmAddress = UserAndHostAndPort.fromParts(machine.getUser(), machine.getAddress().getHostName(), machine.config().get(WinRmMachineLocation.WINRM_PORT)); | ||
getEntity().sensors().set(Attributes.WINRM_ADDRESS, winrmAddress); | ||
|
||
super.start(); | ||
} | ||
|
||
@Override | ||
public boolean isRunning() { | ||
return running.get(); | ||
} | ||
|
||
@Override | ||
public void install() { } | ||
|
||
@Override | ||
public void customize() { } | ||
|
||
@Override | ||
public void copyInstallResources() { | ||
Map<String, String> installFiles = entity.getConfig(SoftwareProcess.INSTALL_FILES); | ||
Map<String, String> installTemplates = entity.getConfig(SoftwareProcess.INSTALL_TEMPLATES); | ||
if ((installFiles!=null && !installFiles.isEmpty()) || (installTemplates!=null && !installTemplates.isEmpty())) { | ||
// only do this if there are files, to prevent unnecessary `mkdir` | ||
super.copyInstallResources(); | ||
} | ||
} | ||
|
||
@Override | ||
public void copyRuntimeResources() { | ||
Map<String, String> runtimeFiles = entity.getConfig(SoftwareProcess.RUNTIME_FILES); | ||
Map<String, String> runtimeTemplates = entity.getConfig(SoftwareProcess.RUNTIME_TEMPLATES); | ||
if ((runtimeFiles!=null && !runtimeFiles.isEmpty()) || (runtimeTemplates!=null && !runtimeTemplates.isEmpty())) { | ||
// only do this if there are files, to prevent unnecessary `mkdir` | ||
super.copyRuntimeResources(); | ||
} | ||
} | ||
|
||
@Override | ||
public void launch() { | ||
running.set(true); | ||
} | ||
|
||
@Override | ||
public void rebind() { | ||
super.rebind(); | ||
/* TODO not necessarily, but there is not yet an easy way to persist state without | ||
* using config/sensors which we might not want do. */ | ||
running.set(true); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
running.set(false); | ||
} | ||
} |