http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsSubnetSshMachineLocation.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsSubnetSshMachineLocation.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsSubnetSshMachineLocation.java index c21810d..d4e8615 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsSubnetSshMachineLocation.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsSubnetSshMachineLocation.java @@ -21,8 +21,7 @@ package org.apache.brooklyn.location.jclouds; import java.util.Map; import org.jclouds.compute.domain.NodeMetadata; - -import org.apache.brooklyn.location.basic.SupportsPortForwarding.RequiresPortForwarding; +import org.apache.brooklyn.location.core.SupportsPortForwarding.RequiresPortForwarding; public abstract class AbstractJcloudsSubnetSshMachineLocation extends JcloudsSshMachineLocation implements RequiresPortForwarding {
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BrooklynMachinePool.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BrooklynMachinePool.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BrooklynMachinePool.java index f52ad0d..dc61807 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BrooklynMachinePool.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BrooklynMachinePool.java @@ -32,10 +32,10 @@ import org.apache.brooklyn.entity.trait.Startable; import org.jclouds.compute.domain.NodeMetadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.brooklyn.location.basic.SshMachineLocation; import org.apache.brooklyn.location.jclouds.pool.MachinePool; import org.apache.brooklyn.location.jclouds.pool.MachineSet; import org.apache.brooklyn.location.jclouds.pool.ReusableMachineTemplate; +import org.apache.brooklyn.location.ssh.SshMachineLocation; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.core.task.BasicExecutionContext; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolver.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolver.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolver.java index 5059a0a..1773470 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolver.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolver.java @@ -32,12 +32,12 @@ import org.apache.brooklyn.api.location.NoMachinesAvailableException; import org.apache.brooklyn.api.mgmt.ManagementContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.brooklyn.location.basic.BasicLocationRegistry; -import org.apache.brooklyn.location.basic.FixedListMachineProvisioningLocation; -import org.apache.brooklyn.location.basic.LocationConfigKeys; -import org.apache.brooklyn.location.basic.LocationConfigUtils; -import org.apache.brooklyn.location.basic.LocationInternal; -import org.apache.brooklyn.location.basic.LocationPropertiesFromBrooklynProperties; +import org.apache.brooklyn.location.byon.FixedListMachineProvisioningLocation; +import org.apache.brooklyn.location.core.BasicLocationRegistry; +import org.apache.brooklyn.location.core.LocationConfigKeys; +import org.apache.brooklyn.location.core.LocationConfigUtils; +import org.apache.brooklyn.location.core.LocationPropertiesFromBrooklynProperties; +import org.apache.brooklyn.location.core.internal.LocationInternal; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.core.config.ConfigBag; import org.apache.brooklyn.util.exceptions.Exceptions; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java index 3d91644..c2f1a28 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java @@ -61,10 +61,10 @@ import org.apache.brooklyn.config.ConfigKey; import org.apache.brooklyn.config.ConfigKey.HasConfigKey; import org.apache.brooklyn.core.config.ConfigUtils; import org.apache.brooklyn.core.config.Sanitizer; -import org.apache.brooklyn.core.mgmt.rebind.persister.LocationWithObjectStore; -import org.apache.brooklyn.core.mgmt.rebind.persister.PersistenceObjectStore; +import org.apache.brooklyn.core.mgmt.persist.LocationWithObjectStore; +import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore; +import org.apache.brooklyn.core.mgmt.persist.jclouds.JcloudsBlobStoreBasedObjectStore; import org.apache.brooklyn.location.access.PortMapping; -import org.apache.brooklyn.location.basic.AbstractLocation; import org.apache.brooklyn.location.cloud.AbstractCloudMachineProvisioningLocation; import org.apache.brooklyn.location.cloud.names.AbstractCloudMachineNamer; import org.apache.brooklyn.location.jclouds.networking.JcloudsPortForwarderExtension; @@ -132,19 +132,18 @@ import com.google.common.io.Files; import com.google.common.net.HostAndPort; import com.google.common.primitives.Ints; -import brooklyn.entity.rebind.persister.jclouds.JcloudsBlobStoreBasedObjectStore; - import org.apache.brooklyn.location.access.PortForwardManager; -import org.apache.brooklyn.location.basic.BasicMachineMetadata; -import org.apache.brooklyn.location.basic.LocationConfigKeys; -import org.apache.brooklyn.location.basic.LocationConfigUtils; -import org.apache.brooklyn.location.basic.LocationConfigUtils.OsCredential; -import org.apache.brooklyn.location.basic.SshMachineLocation; -import org.apache.brooklyn.location.basic.WinRmMachineLocation; import org.apache.brooklyn.location.cloud.AvailabilityZoneExtension; import org.apache.brooklyn.location.cloud.names.CloudMachineNamer; +import org.apache.brooklyn.location.core.AbstractLocation; +import org.apache.brooklyn.location.core.BasicMachineMetadata; +import org.apache.brooklyn.location.core.LocationConfigKeys; +import org.apache.brooklyn.location.core.LocationConfigUtils; +import org.apache.brooklyn.location.core.LocationConfigUtils.OsCredential; import org.apache.brooklyn.location.jclouds.JcloudsPredicates.NodeInLocation; import org.apache.brooklyn.location.jclouds.templates.PortableTemplateBuilder; +import org.apache.brooklyn.location.ssh.SshMachineLocation; +import org.apache.brooklyn.location.winrm.WinRmMachineLocation; import org.apache.brooklyn.util.collections.MutableList; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.collections.MutableSet; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationConfig.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationConfig.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationConfig.java index 03d4432..dd52b75 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationConfig.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationConfig.java @@ -34,8 +34,8 @@ import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.domain.LoginCredentials; import org.apache.brooklyn.location.access.BrooklynAccessUtils; import org.apache.brooklyn.location.access.PortForwardManager; -import org.apache.brooklyn.location.basic.LocationConfigKeys; import org.apache.brooklyn.location.cloud.CloudLocationConfig; +import org.apache.brooklyn.location.core.LocationConfigKeys; import org.apache.brooklyn.util.core.internal.ssh.SshTool; import com.google.common.annotations.Beta; @@ -204,7 +204,7 @@ public interface JcloudsLocationConfig extends CloudLocationConfig { /** * CUSTOM_MACHINE_SETUP_SCRIPT_URL accepts a URL location that points to a shell script. - * Please have a look at locations/jclouds/src/main/resources/sample/script/setup-server.sh as an example + * Please have a look at locations/jclouds/src/main/resources/org/apache/brooklyn/location/jclouds/sample/setup-server.sh as an example */ public static final ConfigKey<String> CUSTOM_MACHINE_SETUP_SCRIPT_URL = ConfigKeys.newStringConfigKey( "setup.script", "Custom script to customize a node"); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationResolver.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationResolver.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationResolver.java index ebb5d57..60ce84f 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationResolver.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationResolver.java @@ -29,16 +29,16 @@ import org.apache.brooklyn.api.location.LocationRegistry; import org.apache.brooklyn.api.location.LocationResolver; import org.apache.brooklyn.api.location.LocationSpec; import org.apache.brooklyn.api.mgmt.ManagementContext; -import org.apache.brooklyn.location.basic.LocationConfigKeys; -import org.apache.brooklyn.location.basic.LocationConfigUtils; -import org.apache.brooklyn.location.basic.LocationInternal; import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.Apis; import org.jclouds.providers.ProviderMetadata; import org.jclouds.providers.Providers; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.brooklyn.location.basic.BasicLocationRegistry; +import org.apache.brooklyn.location.core.BasicLocationRegistry; +import org.apache.brooklyn.location.core.LocationConfigKeys; +import org.apache.brooklyn.location.core.LocationConfigUtils; +import org.apache.brooklyn.location.core.internal.LocationInternal; import org.apache.brooklyn.util.text.Strings; import com.google.common.collect.ImmutableMap; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsMachineLocation.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsMachineLocation.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsMachineLocation.java index 11d20ef..90b4db8 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsMachineLocation.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsMachineLocation.java @@ -19,7 +19,7 @@ package org.apache.brooklyn.location.jclouds; import org.apache.brooklyn.api.location.MachineLocation; -import org.apache.brooklyn.location.basic.HasSubnetHostname; +import org.apache.brooklyn.location.core.HasSubnetHostname; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsPropertiesFromBrooklynProperties.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsPropertiesFromBrooklynProperties.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsPropertiesFromBrooklynProperties.java index 8b2356b..6086d08 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsPropertiesFromBrooklynProperties.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsPropertiesFromBrooklynProperties.java @@ -21,11 +21,11 @@ package org.apache.brooklyn.location.jclouds; import java.util.Map; import org.apache.brooklyn.core.config.ConfigUtils; -import org.apache.brooklyn.location.basic.DeprecatedKeysMappingBuilder; -import org.apache.brooklyn.location.basic.LocationPropertiesFromBrooklynProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.brooklyn.location.basic.LocationConfigKeys; +import org.apache.brooklyn.location.core.DeprecatedKeysMappingBuilder; +import org.apache.brooklyn.location.core.LocationConfigKeys; +import org.apache.brooklyn.location.core.LocationPropertiesFromBrooklynProperties; import org.apache.brooklyn.util.core.config.ConfigBag; import org.apache.brooklyn.util.javalang.JavaClassNames; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java index f315f42..31b414b 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java @@ -34,10 +34,10 @@ import javax.annotation.Nullable; import org.apache.brooklyn.api.location.HardwareDetails; import org.apache.brooklyn.api.location.MachineDetails; import org.apache.brooklyn.api.location.OsDetails; -import org.apache.brooklyn.location.basic.BasicHardwareDetails; -import org.apache.brooklyn.location.basic.BasicMachineDetails; -import org.apache.brooklyn.location.basic.BasicOsDetails; -import org.apache.brooklyn.location.basic.SshMachineLocation; +import org.apache.brooklyn.location.core.BasicHardwareDetails; +import org.apache.brooklyn.location.core.BasicMachineDetails; +import org.apache.brooklyn.location.core.BasicOsDetails; +import org.apache.brooklyn.location.ssh.SshMachineLocation; import org.apache.brooklyn.util.core.flags.SetFromFlag; import org.apache.brooklyn.util.exceptions.Exceptions; import org.apache.brooklyn.util.net.Networking; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsWinRmMachineLocation.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsWinRmMachineLocation.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsWinRmMachineLocation.java index b59ce3e..7b84432 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsWinRmMachineLocation.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsWinRmMachineLocation.java @@ -25,7 +25,7 @@ import java.net.UnknownHostException; import java.util.Iterator; import java.util.Set; -import org.apache.brooklyn.location.basic.WinRmMachineLocation; +import org.apache.brooklyn.location.winrm.WinRmMachineLocation; import org.apache.brooklyn.util.core.flags.SetFromFlag; import org.apache.brooklyn.util.net.Networking; import org.jclouds.compute.domain.NodeMetadata; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/SudoTtyFixingCustomizer.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/SudoTtyFixingCustomizer.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/SudoTtyFixingCustomizer.java index f295790..2552874 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/SudoTtyFixingCustomizer.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/SudoTtyFixingCustomizer.java @@ -18,7 +18,7 @@ */ package org.apache.brooklyn.location.jclouds; -import org.apache.brooklyn.location.basic.SshMachineLocation; +import org.apache.brooklyn.location.ssh.SshMachineLocation; import org.apache.brooklyn.util.core.task.DynamicTasks; import org.apache.brooklyn.util.core.task.ssh.SshTasks; import org.apache.brooklyn.util.core.task.ssh.SshTasks.OnFailingTask; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/java/org/apache/brooklyn/policy/jclouds/os/CreateUserPolicy.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/policy/jclouds/os/CreateUserPolicy.java b/locations/jclouds/src/main/java/org/apache/brooklyn/policy/jclouds/os/CreateUserPolicy.java new file mode 100644 index 0000000..805f1d6 --- /dev/null +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/policy/jclouds/os/CreateUserPolicy.java @@ -0,0 +1,173 @@ +/* + * 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.policy.jclouds.os; + +import java.util.List; + +import org.apache.brooklyn.api.entity.Entity; +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.api.sensor.SensorEvent; +import org.apache.brooklyn.api.sensor.SensorEventListener; +import org.apache.brooklyn.config.ConfigKey; +import org.apache.brooklyn.core.config.ConfigKeys; +import org.apache.brooklyn.entity.core.AbstractEntity; +import org.apache.brooklyn.entity.core.EntityInternal; +import org.apache.brooklyn.location.ssh.SshMachineLocation; +import org.apache.brooklyn.policy.core.AbstractPolicy; +import org.apache.brooklyn.sensor.core.Sensors; +import org.apache.brooklyn.util.core.flags.SetFromFlag; +import org.apache.brooklyn.util.core.internal.ssh.SshTool; +import org.apache.brooklyn.util.text.Identifiers; +import org.jclouds.compute.config.AdminAccessConfiguration; +import org.jclouds.scriptbuilder.functions.InitAdminAccess; +import org.jclouds.scriptbuilder.statements.login.AdminAccess; +import org.jclouds.scriptbuilder.statements.ssh.SshdConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.annotations.Beta; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +/** + * When attached to an entity, this will monitor for when an {@link SshMachineLocation} is added to that entity + * (e.g. when a VM has been provisioned for it). + * + * The policy will then (asynchronously) add a new user to the VM, with a randomly generated password. + * The ssh details will be set as a sensor on the entity. + * + * If this is used, it is strongly encouraged to tell users to change the password on first login. + * + * A preferred mechanism would be for an external key-management tool to generate ssh key-pairs for + * the user, and for the public key to be passed to Brooklyn. However, there is not a customer + * requirement for that yet, so focusing on the password-approach. + */ +@Beta +public class CreateUserPolicy extends AbstractPolicy implements SensorEventListener<Location> { + + // TODO Should add support for authorizing ssh keys as well + + // TODO Should review duplication with: + // - JcloudsLocationConfig.GRANT_USER_SUDO + // (but config default/description and context of use are different) + // - AdminAccess in JcloudsLocation.createUserStatements + + // TODO Could make the password explicitly configurable, or auto-generate if not set? + + private static final Logger LOG = LoggerFactory.getLogger(CreateUserPolicy.class); + + @SetFromFlag("user") + public static final ConfigKey<String> VM_USERNAME = ConfigKeys.newStringConfigKey("createuser.vm.user.name"); + + @SetFromFlag("grantSudo") + public static final ConfigKey<Boolean> GRANT_SUDO = ConfigKeys.newBooleanConfigKey( + "createuser.vm.user.grantSudo", + "Whether to give the new user sudo rights", + false); + + public static final AttributeSensor<String> VM_USER_CREDENTIALS = Sensors.newStringSensor( + "createuser.vm.user.credentials", + "The \"<user> : <password> @ <hostname>:<port>\""); + + public void setEntity(EntityLocal entity) { + super.setEntity(entity); + subscribe(entity, AbstractEntity.LOCATION_ADDED, this); + } + + @Override + public void onEvent(SensorEvent<Location> event) { + final Entity entity = event.getSource(); + final Location loc = event.getValue(); + if (loc instanceof SshMachineLocation) { + addUserAsync(entity, (SshMachineLocation)loc); + } + } + + protected void addUserAsync(final Entity entity, final SshMachineLocation machine) { + ((EntityInternal)entity).getExecutionContext().execute(new Runnable() { + public void run() { + addUser(entity, machine); + }}); + } + + protected void addUser(Entity entity, SshMachineLocation machine) { + boolean grantSudo = getRequiredConfig(GRANT_SUDO); + String user = getRequiredConfig(VM_USERNAME); + String password = Identifiers.makeRandomId(12); + String hostname = machine.getAddress().getHostName(); + int port = machine.getPort(); + String creds = user + " : " + password + " @ " +hostname + ":" + port; + + LOG.info("Adding auto-generated user "+user+" @ "+hostname+":"+port); + + // Build the command to create the user + // Note AdminAccess requires _all_ fields set, due to http://code.google.com/p/jclouds/issues/detail?id=1095 + // If jclouds grants Sudo rights, it overwrites the /etc/sudoers, which makes integration tests very dangerous! Not using it. + AdminAccess adminAccess = AdminAccess.builder() + .adminUsername(user) + .adminPassword(password) + .grantSudoToAdminUser(false) + .resetLoginPassword(true) + .loginPassword(password) + .authorizeAdminPublicKey(false) + .adminPublicKey("ignored") + .installAdminPrivateKey(false) + .adminPrivateKey("ignore") + .lockSsh(false) + .build(); + + org.jclouds.scriptbuilder.domain.OsFamily scriptOsFamily = (machine.getMachineDetails().getOsDetails().isWindows()) + ? org.jclouds.scriptbuilder.domain.OsFamily.WINDOWS + : org.jclouds.scriptbuilder.domain.OsFamily.UNIX; + + InitAdminAccess initAdminAccess = new InitAdminAccess(new AdminAccessConfiguration.Default()); + initAdminAccess.visit(adminAccess); + String cmd = adminAccess.render(scriptOsFamily); + + // Exec command to create the user + int result = machine.execScript(ImmutableMap.of(SshTool.PROP_RUN_AS_ROOT.getName(), true), "create-user-"+user, ImmutableList.of(cmd)); + if (result != 0) { + throw new IllegalStateException("Failed to auto-generate user, using command "+cmd); + } + + // Exec command to grant password-access to sshd (which may have been disabled earlier). + cmd = new SshdConfig(ImmutableMap.of("PasswordAuthentication", "yes")).render(scriptOsFamily); + result = machine.execScript(ImmutableMap.of(SshTool.PROP_RUN_AS_ROOT.getName(), true), "create-user-"+user, ImmutableList.of(cmd)); + if (result != 0) { + throw new IllegalStateException("Failed to enable ssh-login-with-password, using command "+cmd); + } + + // Exec command to grant sudo rights. + if (grantSudo) { + List<String> cmds = ImmutableList.of( + "cat >> /etc/sudoers <<-'END_OF_JCLOUDS_FILE'\n"+ + user+" ALL = (ALL) NOPASSWD:ALL\n"+ + "END_OF_JCLOUDS_FILE\n", + "chmod 0440 /etc/sudoers"); + result = machine.execScript(ImmutableMap.of(SshTool.PROP_RUN_AS_ROOT.getName(), true), "add-user-to-sudoers-"+user, cmds); + if (result != 0) { + throw new IllegalStateException("Failed to auto-generate user, using command "+cmd); + } + } + + ((EntityLocal)entity).setAttribute(VM_USER_CREDENTIALS, creds); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/resources/org/apache/brooklyn/location/jclouds/sample/setup-server.sh ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/resources/org/apache/brooklyn/location/jclouds/sample/setup-server.sh b/locations/jclouds/src/main/resources/org/apache/brooklyn/location/jclouds/sample/setup-server.sh new file mode 100755 index 0000000..cdb5dcc --- /dev/null +++ b/locations/jclouds/src/main/resources/org/apache/brooklyn/location/jclouds/sample/setup-server.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# +# 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. +# +echo Appending nameserver 8.8.8.8 to /etc/resolv.conf +sudo -s -- '/bin/echo nameserver 8.8.8.8 >> /etc/resolv.conf' +unset OS +OS=`head -1 /etc/issue | awk '{ print $1 }'` +unset OS_MAJOR +OS_MAJOR=`head -1 /etc/issue | awk '{ print $4 }' | cut -d'.' -f1` +if [ $OS = "CentOS" -a $OS_MAJOR -eq 6 ]; then + echo Appending options single-request-reopen to /etc/resolv.conf + sudo -s -- '/bin/echo options single-request-reopen >> /etc/resolv.conf' +fi +echo Changing default gateway to ${defaultGateway} +sudo -s -- '/sbin/ip route replace default via ${defaultGateway} dev eth0' http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/main/resources/sample/script/setup-server.sh ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/resources/sample/script/setup-server.sh b/locations/jclouds/src/main/resources/sample/script/setup-server.sh deleted file mode 100755 index cdb5dcc..0000000 --- a/locations/jclouds/src/main/resources/sample/script/setup-server.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -# -# 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. -# -echo Appending nameserver 8.8.8.8 to /etc/resolv.conf -sudo -s -- '/bin/echo nameserver 8.8.8.8 >> /etc/resolv.conf' -unset OS -OS=`head -1 /etc/issue | awk '{ print $1 }'` -unset OS_MAJOR -OS_MAJOR=`head -1 /etc/issue | awk '{ print $4 }' | cut -d'.' -f1` -if [ $OS = "CentOS" -a $OS_MAJOR -eq 6 ]; then - echo Appending options single-request-reopen to /etc/resolv.conf - sudo -s -- '/bin/echo options single-request-reopen >> /etc/resolv.conf' -fi -echo Changing default gateway to ${defaultGateway} -sudo -s -- '/sbin/ip route replace default via ${defaultGateway} dev eth0' http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStoreCleaner.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStoreCleaner.java b/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStoreCleaner.java deleted file mode 100644 index 4b40176..0000000 --- a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStoreCleaner.java +++ /dev/null @@ -1,71 +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.rebind.persister.jclouds; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.domain.PageSet; -import org.jclouds.blobstore.domain.StorageMetadata; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; -import org.apache.brooklyn.location.basic.LocationConfigKeys; -import org.apache.brooklyn.location.cloud.CloudLocationConfig; -import org.apache.brooklyn.location.jclouds.JcloudsLocation; - -/** Utility for cleaning up after test leaks. Most should not leak of course, but if they do... */ -public class BlobStoreCleaner { - - private static String locationSpec = BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC; - - private static final Logger log = LoggerFactory.getLogger(BlobStoreCleaner.class); - - public static void main(String[] args) { - LocalManagementContextForTests mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault()); - JcloudsLocation location = (JcloudsLocation) mgmt.getLocationRegistry().resolve(locationSpec); - - String identity = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_IDENTITY), "identity must not be null"); - String credential = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_CREDENTIAL), "credential must not be null"); - String provider = checkNotNull(location.getConfig(LocationConfigKeys.CLOUD_PROVIDER), "provider must not be null"); - String endpoint = location.getConfig(CloudLocationConfig.CLOUD_ENDPOINT); - - BlobStoreContext context = ContextBuilder.newBuilder(provider) - .credentials(identity, credential) - .endpoint(endpoint) - .buildView(BlobStoreContext.class); - - PageSet<? extends StorageMetadata> containers = context.getBlobStore().list(); - for (StorageMetadata container: containers) { - if (container.getName().matches("brooklyn.*-test.*") - // to kill all containers here -// || container.getName().matches(".*") - ) { - log.info("killing - "+container.getName()); - context.getBlobStore().deleteContainer(container.getName()); - } else { - log.info("KEEPING - "+container.getName()); - } - } - context.close(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStoreExpiryTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStoreExpiryTest.java b/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStoreExpiryTest.java deleted file mode 100644 index b3877dc..0000000 --- a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStoreExpiryTest.java +++ /dev/null @@ -1,196 +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.rebind.persister.jclouds; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.openstack.reference.AuthHeaders.URL_SUFFIX; - -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.List; -import java.util.Map.Entry; - -import org.apache.brooklyn.api.mgmt.ManagementContext; -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.core.http.HttpTool; -import org.apache.brooklyn.util.core.http.HttpToolResponse; -import org.apache.brooklyn.util.text.Identifiers; -import org.apache.brooklyn.util.time.Duration; -import org.apache.brooklyn.util.time.Time; -import org.apache.http.client.HttpClient; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.domain.PageSet; -import org.jclouds.blobstore.domain.StorageMetadata; -import org.jclouds.domain.Credentials; -import org.jclouds.openstack.domain.AuthenticationResponse; -import org.jclouds.openstack.reference.AuthHeaders; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.apache.brooklyn.location.basic.LocationConfigKeys; -import org.apache.brooklyn.location.cloud.CloudLocationConfig; -import org.apache.brooklyn.location.jclouds.JcloudsLocation; -import org.apache.brooklyn.location.jclouds.JcloudsUtil; - -import com.google.common.base.Preconditions; -import com.google.common.cache.LoadingCache; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; -import com.google.inject.Inject; - -@Test(groups={"Live", "Live-sanity"}) -public class BlobStoreExpiryTest { - - private static final Logger log = LoggerFactory.getLogger(BlobStoreExpiryTest.class); - - /** - * Live tests as written require a location defined as follows: - * - * <code> - * brooklyn.location.named.brooklyn-jclouds-objstore-test-1==jclouds:swift:https://ams01.objectstorage.softlayer.net/auth/v1.0 - * brooklyn.location.named.brooklyn-jclouds-objstore-test-1.identity=IBMOS1234-5:yourname - * brooklyn.location.named.brooklyn-jclouds-objstore-test-1.credential=0123abcd....... - * </code> - */ - - public static final String PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC = BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC; - public static final String CONTAINER_PREFIX = "brooklyn-persistence-test"; - private String locationSpec = PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC; - - private JcloudsLocation location; - private BlobStoreContext context; - - private ManagementContext mgmt; - private String testContainerName; - - private String identity; - private String credential; - private String provider; - private String endpoint; - - public synchronized BlobStoreContext getSwiftBlobStoreContext() { - if (context==null) { - if (location==null) { - Preconditions.checkNotNull(locationSpec, "locationSpec required for remote object store when location is null"); - Preconditions.checkNotNull(mgmt, "mgmt required for remote object store when location is null"); - location = (JcloudsLocation) mgmt.getLocationRegistry().resolve(locationSpec); - } - - identity = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_IDENTITY), "identity must not be null"); - credential = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_CREDENTIAL), "credential must not be null"); - provider = checkNotNull(location.getConfig(LocationConfigKeys.CLOUD_PROVIDER), "provider must not be null"); - endpoint = location.getConfig(CloudLocationConfig.CLOUD_ENDPOINT); - - context = JcloudsUtil.newBlobstoreContext(provider, endpoint, identity, credential); - } - return context; - } - - @BeforeMethod(alwaysRun=true) - public void setup() { - testContainerName = CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(8); - mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault()); - } - - @AfterMethod(alwaysRun=true) - public void teardown() { - Entities.destroyAll(mgmt); - if (context!=null) context.close(); - context = null; - } - - public void testRenewAuthSucceedsInSwiftObjectStore() throws Exception { - doTestRenewAuth(); - } - - protected void doTestRenewAuth() throws Exception { - getSwiftBlobStoreContext(); - - injectShortLivedTokenForSwiftAuth(); - - context.getBlobStore().createContainerInLocation(null, testContainerName); - - assertContainerFound(); - - log.info("created container, now sleeping for expiration"); - - Time.sleep(Duration.TEN_SECONDS); - - assertContainerFound(); - - context.getBlobStore().deleteContainer(testContainerName); - } - - private void assertContainerFound() { - PageSet<? extends StorageMetadata> ps = context.getBlobStore().list(); - BlobStoreTest.assertHasItemNamed(ps, testContainerName); - } - - private void injectShortLivedTokenForSwiftAuth() throws Exception { - URL endpointUrl = new URL(endpoint); - - HttpToolResponse tokenHttpResponse1 = requestTokenWithExplicitLifetime(endpointUrl, - identity, credential, Duration.FIVE_SECONDS); - - Builder<String, URI> servicesMapBuilder = ImmutableMap.builder(); - for (Entry<String, List<String>> entry : tokenHttpResponse1.getHeaderLists().entrySet()) { - if (entry.getKey().toLowerCase().endsWith(URL_SUFFIX.toLowerCase()) || - entry.getKey().toLowerCase().endsWith("X-Auth-Token-Expires".toLowerCase())){ - servicesMapBuilder.put(entry.getKey(), URI.create(entry.getValue().iterator().next())); - } - } - AuthenticationResponse authResponse = new AuthenticationResponse(tokenHttpResponse1.getHeaderLists().get(AuthHeaders.AUTH_TOKEN).get(0), servicesMapBuilder.build()); - - getAuthCache().put(new Credentials(identity, credential), authResponse); - } - - private LoadingCache<Credentials, AuthenticationResponse> getAuthCache() { - return context.utils().injector().getInstance(CachePeeker.class).authenticationResponseCache; - } - - public static class CachePeeker { - private final LoadingCache<Credentials, AuthenticationResponse> authenticationResponseCache; - - @Inject - protected CachePeeker(LoadingCache<Credentials, AuthenticationResponse> authenticationResponseCache) { - this.authenticationResponseCache = authenticationResponseCache; - } - } - - public static HttpToolResponse requestTokenWithExplicitLifetime(URL url, String user, String key, Duration expiration) throws URISyntaxException { - HttpClient client = HttpTool.httpClientBuilder().build(); - HttpToolResponse response = HttpTool.httpGet(client, url.toURI(), MutableMap.<String,String>of() - .add(AuthHeaders.AUTH_USER, user) - .add(AuthHeaders.AUTH_KEY, key) - .add("Host", url.getHost()) - .add("X-Auth-New-Token", "" + true) - .add("X-Auth-Token-Lifetime", "" + expiration.toSeconds()) - ); -// curl -v https://ams01.objectstorage.softlayer.net/auth/v1.0/v1.0 -H "X-Auth-User: IBMOS12345-2:username" -H "X-Auth-Key: <API KEY>" -H "Host: ams01.objectstorage.softlayer.net" -H "X-Auth-New-Token: true" -H "X-Auth-Token-Lifetime: 15" - log.info("Requested token with explicit lifetime: "+expiration+" at "+url+"\n"+response+"\n"+response.getHeaderLists()); - return response; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStorePersistencePerformanceTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStorePersistencePerformanceTest.java b/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStorePersistencePerformanceTest.java deleted file mode 100644 index acd5775..0000000 --- a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStorePersistencePerformanceTest.java +++ /dev/null @@ -1,120 +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.rebind.persister.jclouds; - -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode; -import org.apache.brooklyn.core.mgmt.rebind.persister.PersistMode; -import org.apache.brooklyn.core.mgmt.rebind.persister.PersistenceObjectStore.StoreObjectAccessor; -import org.apache.brooklyn.core.test.qa.performance.AbstractPerformanceTest; -import org.apache.brooklyn.util.text.Identifiers; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; - -public class BlobStorePersistencePerformanceTest extends AbstractPerformanceTest { - - public static final String LOCATION_SPEC = "named:brooklyn-jclouds-objstore-test-1"; - - JcloudsBlobStoreBasedObjectStore objectStore; - StoreObjectAccessor blobstoreAccessor; - - @BeforeMethod(alwaysRun=true) - @Override - public void setUp() throws Exception { - super.setUp(); - - objectStore = new JcloudsBlobStoreBasedObjectStore(LOCATION_SPEC, "BlobStorePersistencePerformanceTest"); - objectStore.injectManagementContext(mgmt); - objectStore.prepareForSharedUse(PersistMode.AUTO, HighAvailabilityMode.AUTO); - blobstoreAccessor = objectStore.newAccessor(Identifiers.makeRandomId(8)); - - app.start(ImmutableList.of(loc)); - } - - @AfterMethod(alwaysRun=true) - @Override - public void tearDown() throws Exception { - super.tearDown(); - if (blobstoreAccessor != null) blobstoreAccessor.delete(); - if (objectStore != null) { - objectStore.deleteCompletely(); - objectStore.close(); - } - } - - protected int numIterations() { - return 100; - } - - @Test(groups={"Live", "Acceptance"}) - public void testStoreObjectPuts() throws Exception { - int numIterations = numIterations(); - double minRatePerSec = 10 * PERFORMANCE_EXPECTATION; - final AtomicInteger i = new AtomicInteger(); - - measureAndAssert("StoreObjectAccessor.put", numIterations, minRatePerSec, new Runnable() { - public void run() { - blobstoreAccessor.put(""+i.incrementAndGet()); - }}); - } - - @Test(groups={"Live", "Acceptance"}) - public void testStoreObjectGet() throws Exception { - // The file system will have done a lot of caching here - we are unlikely to touch the disk more than once. - int numIterations = numIterations(); - double minRatePerSec = 10 * PERFORMANCE_EXPECTATION; - - measureAndAssert("FileBasedStoreObjectAccessor.get", numIterations, minRatePerSec, new Runnable() { - public void run() { - blobstoreAccessor.get(); - }}); - } - - @Test(groups={"Live", "Acceptance"}) - public void testStoreObjectDelete() throws Exception { - int numIterations = numIterations(); - double minRatePerSec = 10 * PERFORMANCE_EXPECTATION; - - // Will do 10% warm up runs first - final List<StoreObjectAccessor> blobstoreAccessors = Lists.newArrayList(); - for (int i = 0; i < (numIterations * 1.1 + 1); i++) { - blobstoreAccessors.add(objectStore.newAccessor("storeObjectDelete-"+i)); - } - - final AtomicInteger i = new AtomicInteger(); - - try { - measureAndAssert("FileBasedStoreObjectAccessor.delete", numIterations, minRatePerSec, new Runnable() { - public void run() { - StoreObjectAccessor blobstoreAccessor = blobstoreAccessors.get(i.getAndIncrement()); - blobstoreAccessor.delete(); - }}); - } finally { - for (StoreObjectAccessor blobstoreAccessor : blobstoreAccessors) { - blobstoreAccessor.delete(); - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStoreTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStoreTest.java b/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStoreTest.java deleted file mode 100644 index 65cfda5..0000000 --- a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BlobStoreTest.java +++ /dev/null @@ -1,150 +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.rebind.persister.jclouds; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.io.IOException; - -import org.apache.brooklyn.api.mgmt.ManagementContext; -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.util.stream.Streams; -import org.apache.brooklyn.util.text.Identifiers; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.blobstore.domain.PageSet; -import org.jclouds.blobstore.domain.StorageMetadata; -import org.jclouds.blobstore.options.ListContainerOptions; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.apache.brooklyn.location.basic.LocationConfigKeys; -import org.apache.brooklyn.location.cloud.CloudLocationConfig; -import org.apache.brooklyn.location.jclouds.JcloudsLocation; -import org.apache.brooklyn.location.jclouds.JcloudsUtil; - -import com.google.common.base.Preconditions; - -@Test(groups={"Live", "Live-sanity"}) -public class BlobStoreTest { - - /** - * Live tests as written require a location defined as follows: - * - * <code> - * brooklyn.location.named.brooklyn-jclouds-objstore-test-1==jclouds:swift:https://ams01.objectstorage.softlayer.net/auth/v1.0 - * brooklyn.location.named.brooklyn-jclouds-objstore-test-1.identity=IBMOS1234-5:yourname - * brooklyn.location.named.brooklyn-jclouds-objstore-test-1.credential=0123abcd....... - * </code> - */ - public static final String PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC = "named:brooklyn-jclouds-objstore-test-1"; - - public static final String CONTAINER_PREFIX = "brooklyn-persistence-test"; - - private String locationSpec = PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC; - - private JcloudsLocation location; - private BlobStoreContext context; - - private ManagementContext mgmt; - private String testContainerName; - - public synchronized BlobStoreContext getBlobStoreContext() { - if (context==null) { - if (location==null) { - Preconditions.checkNotNull(locationSpec, "locationSpec required for remote object store when location is null"); - Preconditions.checkNotNull(mgmt, "mgmt required for remote object store when location is null"); - location = (JcloudsLocation) mgmt.getLocationRegistry().resolve(locationSpec); - } - - String identity = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_IDENTITY), "identity must not be null"); - String credential = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_CREDENTIAL), "credential must not be null"); - String provider = checkNotNull(location.getConfig(LocationConfigKeys.CLOUD_PROVIDER), "provider must not be null"); - String endpoint = location.getConfig(CloudLocationConfig.CLOUD_ENDPOINT); - - context = JcloudsUtil.newBlobstoreContext(provider, endpoint, identity, credential); - } - return context; - } - - @BeforeMethod(alwaysRun=true) - public void setup() { - testContainerName = CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(8); - mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault()); - getBlobStoreContext(); - } - - @AfterMethod(alwaysRun=true) - public void teardown() { - Entities.destroyAll(mgmt); - } - - public void testCreateListDestroyContainer() throws IOException { - context.getBlobStore().createContainerInLocation(null, testContainerName); - context.getBlobStore().list(testContainerName); - PageSet<? extends StorageMetadata> ps = context.getBlobStore().list(); - assertHasItemNamed(ps, testContainerName); - - Blob b = context.getBlobStore().blobBuilder("my-blob-1").payload(Streams.newInputStreamWithContents("hello world")).build(); - context.getBlobStore().putBlob(testContainerName, b); - - Blob b2 = context.getBlobStore().getBlob(testContainerName, "my-blob-1"); - Assert.assertEquals(Streams.readFullyString(b2.getPayload().openStream()), "hello world"); - - context.getBlobStore().deleteContainer(testContainerName); - } - - public void testCreateListDestroySimpleDirInContainer() throws IOException { - context.getBlobStore().createContainerInLocation(null, testContainerName); - context.getBlobStore().createDirectory(testContainerName, "my-dir-1"); - - PageSet<? extends StorageMetadata> ps = context.getBlobStore().list(testContainerName); - assertHasItemNamed(ps, "my-dir-1"); - - Blob b = context.getBlobStore().blobBuilder("my-blob-1").payload(Streams.newInputStreamWithContents("hello world")).build(); - context.getBlobStore().putBlob(testContainerName+"/"+"my-dir-1", b); - - ps = context.getBlobStore().list(testContainerName, ListContainerOptions.Builder.inDirectory("my-dir-1")); - assertHasItemNamed(ps, "my-dir-1/my-blob-1"); - - // both these syntaxes work: - Blob b2 = context.getBlobStore().getBlob(testContainerName+"/"+"my-dir-1", "my-blob-1"); - Assert.assertEquals(Streams.readFullyString(b2.getPayload().openStream()), "hello world"); - - Blob b3 = context.getBlobStore().getBlob(testContainerName, "my-dir-1"+"/"+"my-blob-1"); - Assert.assertEquals(Streams.readFullyString(b3.getPayload().openStream()), "hello world"); - - context.getBlobStore().deleteContainer(testContainerName); - } - - static void assertHasItemNamed(PageSet<? extends StorageMetadata> ps, String name) { - if (!hasItemNamed(ps, name)) - Assert.fail("No item named '"+name+"' in "+ps); - } - - static boolean hasItemNamed(PageSet<? extends StorageMetadata> ps, String name) { - for (StorageMetadata sm: ps) - if (name==null || name.equals(sm.getName())) return true; - return false; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BrooklynMementoPersisterJcloudsObjectStoreTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BrooklynMementoPersisterJcloudsObjectStoreTest.java b/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BrooklynMementoPersisterJcloudsObjectStoreTest.java deleted file mode 100644 index 550cc8c..0000000 --- a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/BrooklynMementoPersisterJcloudsObjectStoreTest.java +++ /dev/null @@ -1,66 +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.rebind.persister.jclouds; - - -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; -import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils; -import org.apache.brooklyn.core.mgmt.rebind.persister.BrooklynMementoPersisterTestFixture; -import org.apache.brooklyn.util.text.Identifiers; -import org.apache.brooklyn.util.time.Duration; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -/** - * @author Andrea Turli - */ -@Test(groups={"Live", "Live-sanity"}) -public class BrooklynMementoPersisterJcloudsObjectStoreTest extends BrooklynMementoPersisterTestFixture { - - @Override @BeforeMethod - public void setUp() throws Exception { super.setUp(); } - - protected LocalManagementContext newPersistingManagementContext() { - objectStore = new JcloudsBlobStoreBasedObjectStore( - BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC, BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4)); - return RebindTestUtils.managementContextBuilder(classLoader, objectStore) - .persistPeriod(Duration.ONE_MILLISECOND) - .properties(BrooklynProperties.Factory.newDefault()) - .buildStarted(); - } - - @Test(groups={"Live", "Live-sanity"}) - @Override - public void testCheckPointAndLoadMemento() throws Exception { - super.testCheckPointAndLoadMemento(); - } - - @Test(groups={"Live", "Live-sanity"}) - @Override - public void testDeleteAndLoadMemento() throws Exception { - super.testDeleteAndLoadMemento(); - } - - @Test(groups={"Live", "Live-sanity"}) - @Override - public void testLoadAndCheckpointRawMemento() throws Exception { - super.testLoadAndCheckpointRawMemento(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/EntityToBlobStorePersistencePerformanceTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/EntityToBlobStorePersistencePerformanceTest.java b/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/EntityToBlobStorePersistencePerformanceTest.java deleted file mode 100644 index 92c11fd..0000000 --- a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/EntityToBlobStorePersistencePerformanceTest.java +++ /dev/null @@ -1,64 +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.rebind.persister.jclouds; - -import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; -import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils; -import org.apache.brooklyn.core.test.qa.performance.EntityPersistencePerformanceTest; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.Test; - -public class EntityToBlobStorePersistencePerformanceTest extends EntityPersistencePerformanceTest { - - private static final String LOCATION_SPEC = BlobStorePersistencePerformanceTest.LOCATION_SPEC; - - private JcloudsBlobStoreBasedObjectStore objectStore; - - @Override - protected LocalManagementContext createOrigManagementContext() { - objectStore = new JcloudsBlobStoreBasedObjectStore(LOCATION_SPEC, "EntityToBlobStorePersistencePerformanceTest"); - - return RebindTestUtils.managementContextBuilder(classLoader, objectStore) - .forLive(true) - .persistPeriodMillis(getPersistPeriodMillis()) - .buildStarted(); - } - - @AfterMethod(alwaysRun=true) - @Override - public void tearDown() throws Exception { - super.tearDown(); - if (objectStore != null) { - objectStore.deleteCompletely(); - objectStore.close(); - } - } - - @Test(groups="Live") - @Override - public void testManyEntities() throws Exception { - super.testManyEntities(); - } - - @Test(groups="Live") - @Override - public void testRapidChanges() throws Exception { - super.testRapidChanges(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/HighAvailabilityManagerJcloudsObjectStoreTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/HighAvailabilityManagerJcloudsObjectStoreTest.java b/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/HighAvailabilityManagerJcloudsObjectStoreTest.java deleted file mode 100644 index 3268b0b..0000000 --- a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/HighAvailabilityManagerJcloudsObjectStoreTest.java +++ /dev/null @@ -1,79 +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.rebind.persister.jclouds; - -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.mgmt.ha.HighAvailabilityManagerTestFixture; -import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; -import org.apache.brooklyn.core.mgmt.rebind.persister.PersistenceObjectStore; -import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; -import org.apache.brooklyn.util.text.Identifiers; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -@Test(groups={"Live", "Live-sanity"}) -public class HighAvailabilityManagerJcloudsObjectStoreTest extends HighAvailabilityManagerTestFixture { - - protected ManagementContextInternal newLocalManagementContext() { - return new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault()); - } - - @Override @BeforeMethod - public void setUp() throws Exception { super.setUp(); } - - protected PersistenceObjectStore newPersistenceObjectStore() { - return new JcloudsBlobStoreBasedObjectStore( - BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC, BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4)); - } - - @Test(groups="Live", invocationCount=5) //run fewer times w softlayer... - public void testGetManagementPlaneStatusManyTimes() throws Exception { - testGetManagementPlaneStatus(); - } - - @Test(groups={"Live", "Live-sanity"}) - @Override - public void testDoesNotPromoteIfMasterTimeoutNotExpired() throws Exception { - super.testDoesNotPromoteIfMasterTimeoutNotExpired(); - } - - @Test(groups={"Live", "Live-sanity"}) - @Override - public void testGetManagementPlaneStatus() throws Exception { - super.testGetManagementPlaneStatus(); - } - - @Test(groups={"Live", "Live-sanity"}) - @Override - public void testPromotes() throws Exception { - super.testPromotes(); - } - - @Test(groups={"Live", "Live-sanity"}) - @Override - public void testGetManagementPlaneSyncStateInfersTimedOutNodeAsFailed() throws Exception { - super.testGetManagementPlaneSyncStateInfersTimedOutNodeAsFailed(); - } - - @Test(groups={"Live", "Live-sanity"}) - @Override - public void testGetManagementPlaneSyncStateDoesNotThrowNpeBeforePersisterSet() throws Exception { - super.testGetManagementPlaneSyncStateDoesNotThrowNpeBeforePersisterSet(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/JcloudsBlobStoreBasedObjectStoreTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/JcloudsBlobStoreBasedObjectStoreTest.java b/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/JcloudsBlobStoreBasedObjectStoreTest.java deleted file mode 100644 index fee274d..0000000 --- a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/JcloudsBlobStoreBasedObjectStoreTest.java +++ /dev/null @@ -1,118 +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.rebind.persister.jclouds; - - -import java.util.List; - -import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; -import org.apache.brooklyn.core.mgmt.rebind.persister.BrooklynPersistenceUtils; -import org.apache.brooklyn.core.mgmt.rebind.persister.PersistenceObjectStore; -import org.apache.brooklyn.core.mgmt.rebind.persister.PersistenceObjectStore.StoreObjectAccessor; -import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.util.collections.MutableList; -import org.apache.brooklyn.util.text.Identifiers; -import org.apache.brooklyn.util.time.Duration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.google.common.base.Stopwatch; - -/** - * @author Andrea Turli - */ -@Test(groups={"Live", "Live-sanity"}) -public class JcloudsBlobStoreBasedObjectStoreTest { - - private static final Logger log = LoggerFactory.getLogger(JcloudsBlobStoreBasedObjectStoreTest.class); - - private List<PersistenceObjectStore> objectStores = MutableList.of();; - private LocalManagementContext mgmt; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - mgmt = LocalManagementContextForTests.builder(true).useDefaultProperties().build(); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - for (PersistenceObjectStore store: objectStores) store.deleteCompletely(); - Entities.destroyAll(mgmt); - objectStores.clear(); - } - - public PersistenceObjectStore newObjectStore(String spec, String container) { - PersistenceObjectStore newObjectStore = BrooklynPersistenceUtils.newPersistenceObjectStore(mgmt, spec, container); - objectStores.add(newObjectStore); - return newObjectStore; - } - - @Test(groups={"Integration"}) - public void testLocalhost() throws Exception { - doTestWithStore( newObjectStore(null, - BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4)) ); - } - - @Test(groups={"Integration"}) - public void testLocalhostWithSubPathInContainerName() throws Exception { - doTestWithStore( newObjectStore(null, - BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4)+"/subpath1/subpath2") ); - } - - @Test(groups={"Live", "Live-sanity"}) - public void testJclouds() throws Exception { - doTestWithStore( newObjectStore(BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC, - BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4)) ); - } - - @Test(groups={"Live", "Live-sanity"}) - public void testJcloudsWithSubPathInContainerName() throws Exception { - doTestWithStore( newObjectStore(BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC, - BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4)+"/subpath1/subpath2") ); - } - - protected void doTestWithStore(PersistenceObjectStore objectStore) { - log.info("testing against "+objectStore.getSummaryName()); - - objectStore.createSubPath("foo"); - StoreObjectAccessor f = objectStore.newAccessor("foo/file1.txt"); - Assert.assertFalse(f.exists()); - - Stopwatch timer = Stopwatch.createStarted(); - f.append("Hello world"); - log.info("created in "+Duration.of(timer)); - timer.reset(); - Assert.assertEquals(f.get(), "Hello world"); - log.info("retrieved in "+Duration.of(timer)); - Assert.assertTrue(f.exists()); - - timer.reset(); - List<String> files = objectStore.listContentsWithSubPath("foo"); - log.info("list retrieved in "+Duration.of(timer)+"; is: "+files); - Assert.assertEquals(files, MutableList.of("foo/file1.txt")); - - f.delete(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/JcloudsExpect100ContinueTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/JcloudsExpect100ContinueTest.java b/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/JcloudsExpect100ContinueTest.java deleted file mode 100644 index 43943c6..0000000 --- a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/JcloudsExpect100ContinueTest.java +++ /dev/null @@ -1,148 +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.rebind.persister.jclouds; - -import org.apache.brooklyn.api.mgmt.ManagementContext; -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.util.text.Identifiers; -import org.jclouds.blobstore.BlobStore; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.domain.Blob; -import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.apache.brooklyn.location.jclouds.JcloudsLocation; -import org.apache.brooklyn.location.jclouds.JcloudsUtil; - -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.Logger; - -import com.google.common.base.Charsets; -import com.google.common.io.ByteSource; - -public class JcloudsExpect100ContinueTest { - private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(JcloudsExpect100ContinueTest.class); - - private static String LOCATION_SPEC = BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC; - private static final String OBJECT_NAME_PUT = "test_put"; - private static final String OBJECT_NAME_GET = "test_get"; - - private ManagementContext mgmt; - private BlobStoreContext context; - private String containerName; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - // It's important to disable jclouds debug logging - // as it "fixes" the issue. - setInfoLevel(Logger.ROOT_LOGGER_NAME); - setInfoLevel("jclouds"); - setInfoLevel("org.jclouds"); - - mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault()); - JcloudsLocation jcloudsLocation = (JcloudsLocation) mgmt.getLocationRegistry().resolve(LOCATION_SPEC); - context = JcloudsUtil.newBlobstoreContext( - jcloudsLocation.getProvider(), - jcloudsLocation.getEndpoint(), - jcloudsLocation.getIdentity(), - jcloudsLocation.getCredential()); - containerName = BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(8); - context.getBlobStore().createContainerInLocation(null, containerName); - } - - private void setInfoLevel(String loggerName) { - Logger logger = (Logger) LoggerFactory.getLogger(loggerName); - logger.setLevel(Level.INFO); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - try { - context.getBlobStore().deleteContainer(containerName); - } catch (Exception e){} - context.close(); - Entities.destroyAll(mgmt); - } - - @Test(groups = "Live", timeOut=240000) - public void testPutAfterUnclosedGet() { - put(OBJECT_NAME_PUT, getContent()); - put(OBJECT_NAME_GET, getContent()); - - for (int i = 1; i <= 50; i++) { - long start = System.currentTimeMillis(); - get(OBJECT_NAME_GET); - long afterGet = System.currentTimeMillis(); - LOG.info(i + ". GET @" + (afterGet - start)); - - System.gc(); - System.gc(); - System.gc(); - sleep(1000); - - // Without excluding Expect: 100-Continue header - // the PUT is supposed to block until the server - // times out - - long beforePut = System.currentTimeMillis(); - put(OBJECT_NAME_PUT, getContent()); - long end = System.currentTimeMillis(); - LOG.info(i + ". PUT @" + (end - beforePut)); - } - } - - private String getContent() { - return "1234567890"; - } - - private void put(String name, String content) { - BlobStore blobStore = context.getBlobStore(); - byte[] bytes = content.getBytes(Charsets.UTF_8); - Blob blob = blobStore.blobBuilder(name) - .payload(ByteSource.wrap(bytes)) - .contentLength(bytes.length) - .build(); - try { - blobStore.putBlob(containerName, blob); - } catch (Exception e) { - LOG.error("PUT " + name + " failed", e); - } - } - - private Blob get(String name) { - try { - BlobStore blobStore = context.getBlobStore(); - return blobStore.getBlob(containerName, name); - } catch (Exception e) { - LOG.error("GET " + name + " failed", e); - return null; - } - } - - private void sleep(long millis) { - try { - Thread.sleep(millis); - } catch (InterruptedException e) { - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a1ad34d7/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/JcloudsObjectStoreAccessorWriterTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/JcloudsObjectStoreAccessorWriterTest.java b/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/JcloudsObjectStoreAccessorWriterTest.java deleted file mode 100644 index 76c2bfd..0000000 --- a/locations/jclouds/src/test/java/brooklyn/entity/rebind/persister/jclouds/JcloudsObjectStoreAccessorWriterTest.java +++ /dev/null @@ -1,181 +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.rebind.persister.jclouds; - -import java.io.IOException; - -import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode; -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.mgmt.rebind.persister.PersistMode; -import org.apache.brooklyn.core.mgmt.rebind.persister.PersistenceStoreObjectAccessorWriterTestFixture; -import org.apache.brooklyn.core.mgmt.rebind.persister.StoreObjectAccessorLocking; -import org.apache.brooklyn.core.mgmt.rebind.persister.PersistenceObjectStore.StoreObjectAccessorWithLock; -import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.util.exceptions.Exceptions; -import org.apache.brooklyn.util.net.Urls; -import org.apache.brooklyn.util.text.Identifiers; -import org.apache.brooklyn.util.time.Duration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -@Test(groups={"Live", "Live-sanity"}) -public class JcloudsObjectStoreAccessorWriterTest extends PersistenceStoreObjectAccessorWriterTestFixture { - - private static final Logger log = LoggerFactory.getLogger(JcloudsObjectStoreAccessorWriterTest.class); - - private JcloudsBlobStoreBasedObjectStore store; - private LocalManagementContextForTests mgmt; - - @Override @BeforeMethod - public void setUp() throws Exception { - store = new JcloudsBlobStoreBasedObjectStore( - BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC, BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4)); - store.injectManagementContext(mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault())); - store.prepareForSharedUse(PersistMode.CLEAN, HighAvailabilityMode.DISABLED); - super.setUp(); - } - - @Override @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - super.tearDown(); - if (mgmt!=null) Entities.destroyAll(mgmt); - if (store!=null) store.deleteCompletely(); - } - - protected StoreObjectAccessorWithLock newPersistenceStoreObjectAccessor() throws IOException { - return newPersistenceStoreObjectAccessor(store, ""); - } - protected StoreObjectAccessorWithLock newPersistenceStoreObjectAccessor(JcloudsBlobStoreBasedObjectStore aStore, String prefix) throws IOException { - return new StoreObjectAccessorLocking(aStore.newAccessor(prefix+"sample-file-"+Identifiers.makeRandomId(4))); - } - - @Override - protected Duration getLastModifiedResolution() { - // Not sure what timing resolution is on things like Softlayer's Swift. - // It passed for Aled repeatedly on 2014-11-05 with 2 seconds. - return Duration.seconds(2); - } - - protected int biggishSize() { - // bit smaller since it's actually uploading here! - return 10000; - } - - /** Tests what happen when we ask the store to be in a container with a path, e.g. path1/path2 - * and then the accessor to a file within that (path3/file) -- - * this does it an emulated way, where the store tracks the subpath so we don't have to */ - @Test(groups={"Live"}) - public void testNestedPath1() throws IOException { - mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault()); - String path1 = BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4); - String path2 = BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4); - String path3 = BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4); - JcloudsBlobStoreBasedObjectStore store0 = null; - try { - store0 = new JcloudsBlobStoreBasedObjectStore(BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC, Urls.mergePaths(path1, path2)); - store0.injectManagementContext(mgmt); - store0.prepareForSharedUse(PersistMode.CLEAN, HighAvailabilityMode.DISABLED); - - newPersistenceStoreObjectAccessor(store0, path3+"/").put("hello world"); - } catch (Exception e) { - log.warn("Failed with: "+e, e); - throw Exceptions.propagate(e); - - } finally { - store0.deleteCompletely(); - - JcloudsBlobStoreBasedObjectStore storeD = new JcloudsBlobStoreBasedObjectStore(BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC, path1); - storeD.injectManagementContext(mgmt); - storeD.prepareForSharedUse(PersistMode.CLEAN, HighAvailabilityMode.DISABLED); - storeD.deleteCompletely(); - } - } - - /** Tests what happen when we ask the store to be in a container with a path, e.g. path1/path2 - * and then the accessor to a file within that (path3/file) -- - * this does it the "official" way, where we ask for the store's container - * to be the first path segment */ - @Test(groups={"Live"}) - public void testNestedPath2() throws IOException { - mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault()); - String path1 = BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4); - String path2 = BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4); - String path3 = BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4); - JcloudsBlobStoreBasedObjectStore store1 = null, store2 = null; - try { - store1 = new JcloudsBlobStoreBasedObjectStore(BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC, - path1); - store1.injectManagementContext(mgmt); - store1.prepareForSharedUse(PersistMode.CLEAN, HighAvailabilityMode.DISABLED); - store1.createSubPath(path2); - newPersistenceStoreObjectAccessor(store1, path2+"/"+path3+"/").put("hello world"); - - store2 = new JcloudsBlobStoreBasedObjectStore(BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC, - Urls.mergePaths(path1, path2)); - store2.injectManagementContext(mgmt); - store2.prepareForSharedUse(PersistMode.CLEAN, HighAvailabilityMode.DISABLED); - - newPersistenceStoreObjectAccessor(store2, path3+"/").put("hello world"); - - } catch (Exception e) { - e.printStackTrace(); - } finally { - // this doesn't work -// store2.deleteCompletely(); - // this is how you have to do it: - store1.newAccessor(path2).delete(); - - store1.deleteCompletely(); - } - } - - @Test(groups={"Live", "Live-sanity"}) - @Override - public void testWriteBacklogThenDeleteWillLeaveFileDeleted() throws Exception { - super.testWriteBacklogThenDeleteWillLeaveFileDeleted(); - } - - @Test(groups={"Live", "Live-sanity"}) - @Override - public void testWritesFile() throws Exception { - super.testWritesFile(); - } - - @Test(groups={"Live", "Live-sanity"}) - @Override - public void testLastModifiedTime() throws Exception { - super.testLastModifiedTime(); - } - - @Test(groups={"Live", "Live-sanity"}) - @Override - public void testExists() throws Exception { - super.testExists(); - } - - @Test(groups={"Live", "Live-sanity"}) - @Override - public void testAppendsFile() throws Exception { - super.testAppendsFile(); - } -}
