Skip to content
Permalink
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
aledsage committed Jan 20, 2016
1 parent 7191c7b commit 56f9cdda95451dcf58b80e2aab44c8be34e94d0a
Showing 8 changed files with 294 additions and 1 deletion.
@@ -23,15 +23,21 @@

import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.core.entity.Attributes;
import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.EntityAsserts;
import org.apache.brooklyn.entity.software.base.EmptySoftwareProcess;
import org.apache.brooklyn.location.ssh.SshMachineLocation;
import org.apache.brooklyn.test.EntityTestUtils;
import org.apache.brooklyn.util.collections.Jsonya;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.Test;

import com.google.common.collect.Iterables;

@Test
public class EmptySoftwareProcessYamlTest extends AbstractYamlTest {
private static final Logger log = LoggerFactory.getLogger(EnrichersYamlTest.class);
@@ -99,4 +105,20 @@ public void testWithAppAndEntityLocations() throws Exception {
// TODO this, below, probably should be 'localhost on entity', see #1377
Assert.assertEquals(actualMachine.getParent().getDisplayName(), "localhost on entity");
}

@Test(groups="Integration")
public void testNoSshing() throws Exception {
Entity app = createAndStartApplication(
"location: byon:(hosts=\"1.2.3.4\")",
"services:",
"- type: "+EmptySoftwareProcess.class.getName(),
" brooklyn.config:",
" sshMonitoring.enabled: false",
" "+BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION.getName()+": true");
waitForApplicationTasks(app);

EmptySoftwareProcess entity = Iterables.getOnlyElement(Entities.descendants(app, EmptySoftwareProcess.class));
EntityAsserts.assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, true);
EntityAsserts.assertAttributeEqualsContinually(entity, Attributes.SERVICE_UP, true);
}
}
@@ -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));
}
}
@@ -19,10 +19,14 @@
package org.apache.brooklyn.entity.software.base;

import org.apache.brooklyn.api.entity.ImplementedBy;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;

@ImplementedBy(EmptySoftwareProcessImpl.class)
public interface EmptySoftwareProcess extends SoftwareProcess {

ConfigKey<Boolean> USE_SSH_MONITORING = ConfigKeys.newConfigKey("sshMonitoring.enabled", "SSH monitoring enabled", Boolean.TRUE);

public SoftwareProcessDriver getDriver();

}
@@ -18,6 +18,8 @@
*/
package org.apache.brooklyn.entity.software.base;

import org.apache.brooklyn.core.entity.Attributes;

public class EmptySoftwareProcessImpl extends SoftwareProcessImpl implements EmptySoftwareProcess {

@Override
@@ -28,12 +30,20 @@ public Class<?> getDriverInterface() {
@Override
protected void connectSensors() {
super.connectSensors();
connectServiceUpIsRunning();
if (isSshMonitoringEnabled()) {
connectServiceUpIsRunning();
} else {
sensors().set(Attributes.SERVICE_UP, true);
}
}

@Override
protected void disconnectSensors() {
disconnectServiceUpIsRunning();
super.disconnectSensors();
}

protected boolean isSshMonitoringEnabled() {
return Boolean.TRUE.equals(getConfig(USE_SSH_MONITORING));
}
}
@@ -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);
}
@@ -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 {
}
@@ -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));
}
}
@@ -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);
}
}

0 comments on commit 56f9cdd

Please sign in to comment.