http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/brooklyn/location/LocationSpec.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/brooklyn/location/LocationSpec.java b/api/src/main/java/brooklyn/location/LocationSpec.java deleted file mode 100644 index d91ca93..0000000 --- a/api/src/main/java/brooklyn/location/LocationSpec.java +++ /dev/null @@ -1,229 +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.location; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Collections; -import java.util.Map; - -import org.apache.brooklyn.api.basic.AbstractBrooklynObjectSpec; -import org.apache.brooklyn.api.management.Task; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import brooklyn.config.ConfigKey; -import brooklyn.config.ConfigKey.HasConfigKey; - -import com.google.common.collect.Maps; - -/** - * Gives details of a location to be created. It describes the location's configuration, and is - * reusable to create multiple locations with the same configuration. - * - * To create a LocationSpec, it is strongly encouraged to use {@code create(...)} methods. - * - * @param <T> The type of location to be created - * - * @author aled - */ -public class LocationSpec<T extends Location> extends AbstractBrooklynObjectSpec<T,LocationSpec<T>> { - - // TODO Would like to add `configure(ConfigBag)`, but `ConfigBag` is in core rather than api - - private static final Logger log = LoggerFactory.getLogger(LocationSpec.class); - - private final static long serialVersionUID = 1L; - - /** - * Creates a new {@link LocationSpec} instance for a location of the given type. The returned - * {@link LocationSpec} can then be customized. - * - * @param type A {@link Location} class - */ - public static <T extends Location> LocationSpec<T> create(Class<T> type) { - return new LocationSpec<T>(type); - } - - /** - * Creates a new {@link LocationSpec} instance with the given config, for a location of the given type. - * - * This is primarily for groovy code; equivalent to {@code LocationSpec.create(type).configure(config)}. - * - * @param config The spec's configuration (see {@link LocationSpec#configure(Map)}). - * @param type A {@link Location} class - */ - public static <T extends Location> LocationSpec<T> create(Map<?,?> config, Class<T> type) { - return LocationSpec.create(type).configure(config); - } - - /** - * Copies entity spec so its configuration can be overridden without modifying the - * original entity spec. - */ - public static <T extends Location> LocationSpec<T> create(LocationSpec<T> spec) { - // need this to get LocationSpec<T> rather than LocationSpec<? extends T> - @SuppressWarnings("unchecked") - Class<T> exactType = (Class<T>)spec.getType(); - - LocationSpec<T> result = create(exactType) - .displayName(spec.getDisplayName()) - .tags(spec.getTags()) - .configure(spec.getConfig()) - .configure(spec.getFlags()) - .catalogItemId(spec.getCatalogItemId()) - .extensions(spec.getExtensions()); - - if (spec.getParent() != null) result.parent(spec.getParent()); - - return (LocationSpec<T>) result; - } - - private String id; - private Location parent; - private final Map<String, Object> flags = Maps.newLinkedHashMap(); - private final Map<ConfigKey<?>, Object> config = Maps.newLinkedHashMap(); - private final Map<Class<?>, Object> extensions = Maps.newLinkedHashMap(); - - protected LocationSpec(Class<T> type) { - super(type); - } - - protected void checkValidType(Class<? extends T> type) { - checkIsImplementation(type, Location.class); - checkIsNewStyleImplementation(type); - } - - /** - * @deprecated since 0.7.0; instead let the management context pick a random+unique id - */ - @Deprecated - public LocationSpec<T> id(String val) { - id = val; - return this; - } - - public LocationSpec<T> parent(Location val) { - parent = checkNotNull(val, "parent"); - return this; - } - - public LocationSpec<T> configure(Map<?,?> val) { - for (Map.Entry<?, ?> entry: val.entrySet()) { - if (entry.getKey()==null) throw new NullPointerException("Null key not permitted"); - if (entry.getKey() instanceof CharSequence) - flags.put(entry.getKey().toString(), entry.getValue()); - else if (entry.getKey() instanceof ConfigKey<?>) - config.put((ConfigKey<?>)entry.getKey(), entry.getValue()); - else if (entry.getKey() instanceof HasConfigKey<?>) - config.put(((HasConfigKey<?>)entry.getKey()).getConfigKey(), entry.getValue()); - else { - log.warn("Spec "+this+" ignoring unknown config key "+entry.getKey()); - } - } - return this; - } - - public LocationSpec<T> configure(CharSequence key, Object val) { - flags.put(checkNotNull(key, "key").toString(), val); - return this; - } - - public <V> LocationSpec<T> configure(ConfigKey<V> key, V val) { - config.put(checkNotNull(key, "key"), val); - return this; - } - - public <V> LocationSpec<T> configureIfNotNull(ConfigKey<V> key, V val) { - return (val != null) ? configure(key, val) : this; - } - - public <V> LocationSpec<T> configure(ConfigKey<V> key, Task<? extends V> val) { - config.put(checkNotNull(key, "key"), val); - return this; - } - - public <V> LocationSpec<T> configure(HasConfigKey<V> key, V val) { - config.put(checkNotNull(key, "key").getConfigKey(), val); - return this; - } - - public <V> LocationSpec<T> configure(HasConfigKey<V> key, Task<? extends V> val) { - config.put(checkNotNull(key, "key").getConfigKey(), val); - return this; - } - - public <V> LocationSpec<T> removeConfig(ConfigKey<V> key) { - config.remove( checkNotNull(key, "key") ); - return this; - } - - public <E> LocationSpec<T> extension(Class<E> extensionType, E extension) { - extensions.put(checkNotNull(extensionType, "extensionType"), checkNotNull(extension, "extension")); - return this; - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public <E> LocationSpec<T> extensions(Map<Class<?>, ?> extensions) { - for (Map.Entry<Class<?>, ?> entry : extensions.entrySet()) { - extension((Class)entry.getKey(), entry.getValue()); - } - return this; - } - - /** - * @return The id of the location to be created, or null if brooklyn can auto-generate an id - * - * @deprecated since 0.7.0; instead let the management context pick a random+unique id - */ - @Deprecated - public String getId() { - return id; - } - - /** - * @return The location's parent - */ - public Location getParent() { - return parent; - } - - /** - * @return Read-only construction flags - * @see SetFromFlag declarations on the location type - */ - public Map<String, ?> getFlags() { - return Collections.unmodifiableMap(flags); - } - - /** - * @return Read-only configuration values - */ - public Map<ConfigKey<?>, Object> getConfig() { - return Collections.unmodifiableMap(config); - } - - /** - * @return Read-only extension values - */ - public Map<Class<?>, Object> getExtensions() { - return Collections.unmodifiableMap(extensions); - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/brooklyn/location/LocationType.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/brooklyn/location/LocationType.java b/api/src/main/java/brooklyn/location/LocationType.java deleted file mode 100644 index dceabe3..0000000 --- a/api/src/main/java/brooklyn/location/LocationType.java +++ /dev/null @@ -1,32 +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.location; - -import org.apache.brooklyn.api.basic.BrooklynType; - -import com.google.common.annotations.Beta; - -/** - * Gives type information for a {@link Location}. It is immutable. - - * @since 0.7.0 - */ -@Beta -public interface LocationType extends BrooklynType { -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/brooklyn/location/MachineDetails.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/brooklyn/location/MachineDetails.java b/api/src/main/java/brooklyn/location/MachineDetails.java deleted file mode 100644 index 4c3ed13..0000000 --- a/api/src/main/java/brooklyn/location/MachineDetails.java +++ /dev/null @@ -1,34 +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.location; - -import javax.annotation.Nonnull; - -/** - * @since 0.7.0 - */ -public interface MachineDetails { - - @Nonnull - HardwareDetails getHardwareDetails(); - - @Nonnull - OsDetails getOsDetails(); - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/brooklyn/location/MachineLocation.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/brooklyn/location/MachineLocation.java b/api/src/main/java/brooklyn/location/MachineLocation.java deleted file mode 100644 index 0fde48a..0000000 --- a/api/src/main/java/brooklyn/location/MachineLocation.java +++ /dev/null @@ -1,46 +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.location; - -import java.net.InetAddress; - -import brooklyn.util.net.HasNetworkAddresses; - -/** - * A location that is a machine. - * - * This interface marks a {@link Location} being a network node with an IP address, - * and supports appropriate operations on the node. - */ -public interface MachineLocation extends AddressableLocation, HasNetworkAddresses { - /** - * @return the machine's network address. - */ - InetAddress getAddress(); - - /** @deprecated since 0.7.0. Use getMachineDetails().getOsDetails() instead. */ - @Deprecated - OsDetails getOsDetails(); - - /* - * @return hardware and operating system-specific details for the machine. - */ - MachineDetails getMachineDetails(); - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/brooklyn/location/MachineLocationCustomizer.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/brooklyn/location/MachineLocationCustomizer.java b/api/src/main/java/brooklyn/location/MachineLocationCustomizer.java deleted file mode 100644 index 83e1009..0000000 --- a/api/src/main/java/brooklyn/location/MachineLocationCustomizer.java +++ /dev/null @@ -1,42 +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.location; - -import com.google.common.annotations.Beta; - -/** - * Customization hooks to allow apps to perform specific customisation of obtained machines. - * <p> - * Users are strongly encouraged to sub-class {@link BasicMachineLocationCustomizer}, to give - * some protection against this {@link Beta} API changing in future releases. - */ -@Beta -public interface MachineLocationCustomizer { - - /** - * Override to configure the given machine once it has been created (prior to any use). - */ - void customize(MachineLocation machine); - - /** - * Override to handle machine-related cleanup prior to {@link MachineProvisioningLocation} - * releasing the machine. - */ - void preRelease(MachineLocation machine); -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/brooklyn/location/MachineManagementMixins.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/brooklyn/location/MachineManagementMixins.java b/api/src/main/java/brooklyn/location/MachineManagementMixins.java deleted file mode 100644 index 99038ba..0000000 --- a/api/src/main/java/brooklyn/location/MachineManagementMixins.java +++ /dev/null @@ -1,92 +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.location; - -import java.util.Map; - -import com.google.common.annotations.Beta; - -/** - * Defines mixins for interesting locations. - */ -public class MachineManagementMixins { - - public interface RichMachineProvisioningLocation<T extends MachineLocation> extends - MachineProvisioningLocation<T>, ListsMachines, GivesMachineMetadata, KillsMachines {} - - public interface ListsMachines { - /** - * @return A map of machine ID to metadata record for all machines known in a given cloud location. - */ - Map<String,MachineMetadata> listMachines(); - } - - public interface GivesMachineMetadata { - /** - * @return the {@link MachineMetadata} for a given (brooklyn) machine location instance, - * or null if not matched. - */ - MachineMetadata getMachineMetadata(MachineLocation location); - } - - public interface KillsMachines { - /** Kills the indicated machine; throws if not recognised or possible */ - void killMachine(MachineLocation machine); - - /** Kills the machine indicated by the given (server-side) machine id; - * note, the ID is the _cloud-service_ ID, - * that is, pass in getMetadata(machineLocation).getId() not the machineLocation.getId() */ - void killMachine(String cloudServiceId); - } - - /** very lightweight machine record */ - public interface MachineMetadata { - /** The cloud service ID -- distinct from any Brooklyn {@link Location#getId()} */ - String getId(); - String getName(); - String getPrimaryIp(); - Boolean isRunning(); - /** original metadata object, if available; e.g. ComputeMetadata when using jclouds */ - Object getOriginalMetadata(); - } - - /** - * Implement to indicate that a location can suspend and resume machines. - */ - @Beta - public interface SuspendResumeLocation extends SuspendsMachines, ResumesMachines {}; - - - @Beta - public interface SuspendsMachines { - /** - * Suspend the indicated machine. - */ - void suspendMachine(MachineLocation location); - } - - @Beta - public interface ResumesMachines { - /** - * Resume the indicated machine. - */ - void resumeMachine(MachineLocation location); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/brooklyn/location/MachineProvisioningLocation.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/brooklyn/location/MachineProvisioningLocation.java b/api/src/main/java/brooklyn/location/MachineProvisioningLocation.java deleted file mode 100644 index 8553480..0000000 --- a/api/src/main/java/brooklyn/location/MachineProvisioningLocation.java +++ /dev/null @@ -1,72 +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.location; - -import java.util.Collection; -import java.util.Map; - -/** - * A location that is able to provision new machines within its location. - * - * This interface extends {@link Location} to add the ability to provision {@link MachineLocation}s in this location. - */ -public interface MachineProvisioningLocation<T extends MachineLocation> extends ProvisioningLocation<T> { - /** - * Obtain a machine in this location. - * - * @param flags Details of the desired machine (e.g. image, size, open ports, etc; some flag support is limited to selected providers). - * "callerContext" can be specified to have custom logging and error messages (useful if starting machines in parallel) - * @return a machine that is a child of this location. - * @throws NoMachinesAvailableException if there are no machines available in this location (or impls may return null, but that is discouraged) - */ - @Override - T obtain(Map<?,?> flags) throws NoMachinesAvailableException; - - /** - * Creates a new location of the same type, but with additional creation instructions in the form of flags, - * e.g. for specifying subnets, security groups, etc - * <p> - * Implementers who wish to subclass this provisioning location for additional functionality - * in a specific cloud can use the relevant implementation of this method as a guide. - */ - MachineProvisioningLocation<T> newSubLocation(Map<?,?> newFlags); - - /** - * Release a previously-obtained machine. - * - * @param machine a {@link MachineLocation} previously obtained from a call to {@link #obtain()} - * @throws IllegalStateException if the machine did not come from a call to {@link #obtain()} or it has already been released. - */ - @Override - void release(T machine); - - /** - * Gets flags, suitable as an argument to {@link #obtain(Map)}. The tags provided give - * hints about the machine required. The provisioning-location could be configured to - * understand those tags. - * - * For example, an AWS-location could be configured to understand that a particular entity - * type (e.g. "TomcatServer") requires a particular AMI in that region, so would return the - * required image id. - * - * @param tags - * @return - */ - Map<String,Object> getProvisioningFlags(Collection<String> tags); -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/brooklyn/location/NoMachinesAvailableException.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/brooklyn/location/NoMachinesAvailableException.java b/api/src/main/java/brooklyn/location/NoMachinesAvailableException.java deleted file mode 100644 index 0c0201e..0000000 --- a/api/src/main/java/brooklyn/location/NoMachinesAvailableException.java +++ /dev/null @@ -1,35 +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.location; - - -/** - * Indicates no machines are available in a given location. - */ -public class NoMachinesAvailableException extends LocationNotAvailableException { - private static final long serialVersionUID = 1079817235289265761L; - - public NoMachinesAvailableException(String s) { - super(s); - } - - public NoMachinesAvailableException(String s, Throwable throwable) { - super(s, throwable); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/brooklyn/location/OsDetails.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/brooklyn/location/OsDetails.java b/api/src/main/java/brooklyn/location/OsDetails.java deleted file mode 100644 index 8eb69a2..0000000 --- a/api/src/main/java/brooklyn/location/OsDetails.java +++ /dev/null @@ -1,46 +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.location; - -import javax.annotation.Nullable; - -public interface OsDetails { - - /** The name of the operating system, e.g. "Debian" or "Red Hat Enterprise Linux Server" */ - @Nullable - String getName(); - - /** - * The version of the operating system. Generally numeric (e.g. "6.3") but occasionally - * alphabetic (e.g. Debian's "Squeeze"). - */ - @Nullable - String getVersion(); - - /** The operating system's architecture, e.g. "x86" or "x86_64" */ - @Nullable - String getArch(); - - boolean is64bit(); - - boolean isWindows(); - boolean isLinux(); - boolean isMac(); - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/brooklyn/location/PortRange.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/brooklyn/location/PortRange.java b/api/src/main/java/brooklyn/location/PortRange.java deleted file mode 100644 index c523b9a..0000000 --- a/api/src/main/java/brooklyn/location/PortRange.java +++ /dev/null @@ -1,48 +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.location; - -/** - * A range of ports (indicator for Location and other APIs). - * Using methods {@code PortRanges.fromXxx(...)} this is adaptable from a number, a string, or a collection of numbers or a strings. - * String may be of the form: - * <li> "80": just 80 - * <li> "8080-8090": limited range sequentially; ie try 8080, then 8081, ..., then 8090, then give up - * <li> "8080-8000": as above, but descending; ie try 8080, then 8079, ..., then 8000, then give up - * <li> "8000+": unlimited range sequentially; ie try 8000, then 8001, then 8002, etc - * <li> "80,8080,8000,8080-8099": different ranges, in order; ie try 80, then 8080, then 8000, then 8080 (again), then 8081, ..., then 8099, then give up - * Ranges (but not lists) may be preceeded by "!" to indicate a randomly selected port: - * - * @see brooklyn.location.basic.PortRanges - */ -//MAYDO could have: <li> "~32168-65535" (or "~32168-"): try randomly selected numbers in range 32168-65535 (MAX_PORT) until all have been tried -public interface PortRange extends Iterable<Integer> { - /** - * Whether there are any ports in the range. - */ - boolean isEmpty(); - - /** - * Note: this method is only here for use with "groovy truth". Users are strongly discouraged - * from calling it directly. - * - * @return {@code !isEmpty()}; i.e. true if there is at least one port in the range; false otherwise - */ - boolean asBoolean(); -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/brooklyn/location/PortSupplier.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/brooklyn/location/PortSupplier.java b/api/src/main/java/brooklyn/location/PortSupplier.java deleted file mode 100644 index df74fcc..0000000 --- a/api/src/main/java/brooklyn/location/PortSupplier.java +++ /dev/null @@ -1,50 +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.location; - -/** Mixin interface for location which allows it to supply ports from a given range */ -public interface PortSupplier { - - /** - * Reserve a specific port for an application. If your application requires a specific port - for example, port 80 for a web - * server - you should reserve this port before starting your application. Using this method, you will be able to detect if - * another application has already claimed this port number. - * - * @param portNumber the required port number. - * @return {@code true} if the port was successfully reserved; {@code false} if it has been previously reserved. - */ - boolean obtainSpecificPort(int portNumber); - - /** - * Reserve a port for your application, with a port number in a specific range. If your application requires a port, but it does - * not mind exactly which port number - for example, a port for internal JMX monitoring - call this method. - * - * @param range the range of acceptable port numbers. - * @return the port number that has been reserved, or -1 if there was no available port in the acceptable range. - */ - int obtainPort(PortRange range); - - /** - * Release a previously reserved port. - * - * @param portNumber the port number from a call to {@link #obtainPort(PortRange)} or {@link #obtainSpecificPort(int)} - */ - void releasePort(int portNumber); - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/brooklyn/location/ProvisioningLocation.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/brooklyn/location/ProvisioningLocation.java b/api/src/main/java/brooklyn/location/ProvisioningLocation.java deleted file mode 100644 index 88d68f5..0000000 --- a/api/src/main/java/brooklyn/location/ProvisioningLocation.java +++ /dev/null @@ -1,44 +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.location; - -import java.util.Map; - -/** - * A location that is able to provision new locations within it. - */ -public interface ProvisioningLocation<T extends Location> extends Location { - /** - * Obtain a new (sub)-location in the location represented by this class. - * - * @param flags Constraints and details of the location to be provisioned - * @return the location provisioned - * @throws LocationNotAvailableException if could not provision such a location - */ - T obtain(Map<?,?> flags) throws LocationNotAvailableException; - - /** - * Release a previously-obtained location. - * - * @param location a location previously obtained - * @throws IllegalStateException if the machine did not come from a call to {@link #obtain()} or it has already been released. - */ - void release(T machine); - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java b/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java index 5f1b1aa..844996a 100644 --- a/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java +++ b/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java @@ -34,7 +34,7 @@ import org.apache.brooklyn.policy.PolicySpec; import brooklyn.config.ConfigKey; import brooklyn.config.ConfigKey.HasConfigKey; -import brooklyn.location.Location; +import org.apache.brooklyn.location.Location; import brooklyn.util.guava.Maybe; /** http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/api/entity/drivers/EntityDriver.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/api/entity/drivers/EntityDriver.java b/api/src/main/java/org/apache/brooklyn/api/entity/drivers/EntityDriver.java index 16b4a83..7ba0966 100644 --- a/api/src/main/java/org/apache/brooklyn/api/entity/drivers/EntityDriver.java +++ b/api/src/main/java/org/apache/brooklyn/api/entity/drivers/EntityDriver.java @@ -20,7 +20,7 @@ package org.apache.brooklyn.api.entity.drivers; import org.apache.brooklyn.api.entity.basic.EntityLocal; -import brooklyn.location.Location; +import org.apache.brooklyn.location.Location; import com.google.common.annotations.Beta; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/api/entity/drivers/EntityDriverManager.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/api/entity/drivers/EntityDriverManager.java b/api/src/main/java/org/apache/brooklyn/api/entity/drivers/EntityDriverManager.java index 45bc7a4..fe7134b 100644 --- a/api/src/main/java/org/apache/brooklyn/api/entity/drivers/EntityDriverManager.java +++ b/api/src/main/java/org/apache/brooklyn/api/entity/drivers/EntityDriverManager.java @@ -18,7 +18,7 @@ */ package org.apache.brooklyn.api.entity.drivers; -import brooklyn.location.Location; +import org.apache.brooklyn.location.Location; /** * Responsible for creating a driver for a given entity/location. Also used for customizing which http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/api/entity/proxying/EntitySpec.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/api/entity/proxying/EntitySpec.java b/api/src/main/java/org/apache/brooklyn/api/entity/proxying/EntitySpec.java index b55a2d1..5af103a 100644 --- a/api/src/main/java/org/apache/brooklyn/api/entity/proxying/EntitySpec.java +++ b/api/src/main/java/org/apache/brooklyn/api/entity/proxying/EntitySpec.java @@ -40,7 +40,7 @@ import org.slf4j.LoggerFactory; import brooklyn.config.ConfigKey; import brooklyn.config.ConfigKey.HasConfigKey; -import brooklyn.location.Location; +import org.apache.brooklyn.location.Location; import brooklyn.util.collections.MutableList; import com.google.common.base.Supplier; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/api/entity/proxying/EntityTypeRegistry.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/api/entity/proxying/EntityTypeRegistry.java b/api/src/main/java/org/apache/brooklyn/api/entity/proxying/EntityTypeRegistry.java index 53cf6bf..5b55a54 100644 --- a/api/src/main/java/org/apache/brooklyn/api/entity/proxying/EntityTypeRegistry.java +++ b/api/src/main/java/org/apache/brooklyn/api/entity/proxying/EntityTypeRegistry.java @@ -22,7 +22,7 @@ import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.entity.drivers.DriverDependentEntity; import org.apache.brooklyn.api.entity.drivers.EntityDriver; -import brooklyn.location.Location; +import org.apache.brooklyn.location.Location; /** * A registry of the entity implementations to be used when creating an entity of a given type. http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/api/entity/rebind/BrooklynObjectType.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/api/entity/rebind/BrooklynObjectType.java b/api/src/main/java/org/apache/brooklyn/api/entity/rebind/BrooklynObjectType.java index 56883fd..74f10ff 100644 --- a/api/src/main/java/org/apache/brooklyn/api/entity/rebind/BrooklynObjectType.java +++ b/api/src/main/java/org/apache/brooklyn/api/entity/rebind/BrooklynObjectType.java @@ -25,7 +25,7 @@ import org.apache.brooklyn.api.entity.Feed; import org.apache.brooklyn.policy.Enricher; import org.apache.brooklyn.policy.Policy; -import brooklyn.location.Location; +import org.apache.brooklyn.location.Location; import com.google.common.annotations.Beta; import com.google.common.base.CaseFormat; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/api/entity/rebind/RebindExceptionHandler.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/api/entity/rebind/RebindExceptionHandler.java b/api/src/main/java/org/apache/brooklyn/api/entity/rebind/RebindExceptionHandler.java index 39d3613..4b613c3 100644 --- a/api/src/main/java/org/apache/brooklyn/api/entity/rebind/RebindExceptionHandler.java +++ b/api/src/main/java/org/apache/brooklyn/api/entity/rebind/RebindExceptionHandler.java @@ -28,7 +28,7 @@ import org.apache.brooklyn.api.entity.basic.EntityLocal; import org.apache.brooklyn.policy.Enricher; import org.apache.brooklyn.policy.Policy; -import brooklyn.location.Location; +import org.apache.brooklyn.location.Location; import com.google.common.annotations.Beta; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/api/management/AccessController.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/api/management/AccessController.java b/api/src/main/java/org/apache/brooklyn/api/management/AccessController.java index 1342d3b..a8b6939 100644 --- a/api/src/main/java/org/apache/brooklyn/api/management/AccessController.java +++ b/api/src/main/java/org/apache/brooklyn/api/management/AccessController.java @@ -20,7 +20,7 @@ package org.apache.brooklyn.api.management; import org.apache.brooklyn.api.entity.Entity; -import brooklyn.location.Location; +import org.apache.brooklyn.location.Location; import com.google.common.annotations.Beta; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/api/management/LocationManager.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/api/management/LocationManager.java b/api/src/main/java/org/apache/brooklyn/api/management/LocationManager.java index a6fed43..9e4377c 100644 --- a/api/src/main/java/org/apache/brooklyn/api/management/LocationManager.java +++ b/api/src/main/java/org/apache/brooklyn/api/management/LocationManager.java @@ -21,8 +21,8 @@ package org.apache.brooklyn.api.management; import java.util.Collection; import java.util.Map; -import brooklyn.location.Location; -import brooklyn.location.LocationSpec; +import org.apache.brooklyn.location.Location; +import org.apache.brooklyn.location.LocationSpec; /** * For managing and querying entities. http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/api/management/ManagementContext.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/api/management/ManagementContext.java b/api/src/main/java/org/apache/brooklyn/api/management/ManagementContext.java index 404aa56..615982b 100644 --- a/api/src/main/java/org/apache/brooklyn/api/management/ManagementContext.java +++ b/api/src/main/java/org/apache/brooklyn/api/management/ManagementContext.java @@ -34,7 +34,7 @@ import org.apache.brooklyn.api.management.entitlement.EntitlementManager; import org.apache.brooklyn.api.management.ha.HighAvailabilityManager; import brooklyn.config.StringConfigMap; -import brooklyn.location.LocationRegistry; +import org.apache.brooklyn.location.LocationRegistry; import brooklyn.util.guava.Maybe; import com.google.common.annotations.Beta; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/AddressableLocation.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/AddressableLocation.java b/api/src/main/java/org/apache/brooklyn/location/AddressableLocation.java new file mode 100644 index 0000000..ba44467 --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/AddressableLocation.java @@ -0,0 +1,43 @@ +/* + * 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.location; + +import java.net.InetAddress; + +/** A location that has an IP address. + * <p> + * This IP address may be a machine (usually the MachineLocation sub-interface), + * or often an entry point for a service. + */ +public interface AddressableLocation extends Location { + + /** + * Return the single most appropriate address for this location. + * (An implementation or sub-interface definition may supply more information + * on the precise semantics of the address.) + * + * Should not return null, but in some "special cases" (e.g. CloudFoundryLocation it + * may return null if the location is not configured correctly). Users should expect + * a non-null result and treat null as a programming error or misconfiguration. + * Implementors of this interface should strive to not return null (and then we'll + * remove this caveat from the javadoc!). + */ + InetAddress getAddress(); + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/BasicMachineLocationCustomizer.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/BasicMachineLocationCustomizer.java b/api/src/main/java/org/apache/brooklyn/location/BasicMachineLocationCustomizer.java new file mode 100644 index 0000000..bbf53d3 --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/BasicMachineLocationCustomizer.java @@ -0,0 +1,41 @@ +/* + * 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.location; + +import com.google.common.annotations.Beta; + +/** + * A default no-op implementation, which can be extended to override the appropriate methods. + * + * Sub-classing will give the user some protection against future API changes - note that + * {@link MachineLocationCustomizer} is marked {@link Beta}. + */ +@Beta +public class BasicMachineLocationCustomizer implements MachineLocationCustomizer { + + @Override + public void customize(MachineLocation machine) { + // no-op + } + + @Override + public void preRelease(MachineLocation machine) { + // no-op + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/HardwareDetails.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/HardwareDetails.java b/api/src/main/java/org/apache/brooklyn/location/HardwareDetails.java new file mode 100644 index 0000000..58acb0b --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/HardwareDetails.java @@ -0,0 +1,40 @@ +/* + * 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.location; + +import javax.annotation.Nullable; + +/** + * @since 0.7.0 + */ +public interface HardwareDetails { + + /** + * The number of CPUs on the machine + */ + @Nullable + Integer getCpuCount(); + + /** + * Amount of RAM in megabytes + */ + @Nullable + Integer getRam(); + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/Location.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/Location.java b/api/src/main/java/org/apache/brooklyn/location/Location.java new file mode 100644 index 0000000..88a5bfb --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/Location.java @@ -0,0 +1,146 @@ +/* + * 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.location; + +import java.io.Serializable; +import java.util.Collection; +import java.util.Map; + +import org.apache.brooklyn.api.basic.BrooklynObject; + +import brooklyn.config.ConfigKey; +import brooklyn.config.ConfigKey.HasConfigKey; + +/** + * A location that an entity can be in. Examples of locations include a single machine + * or a pool of machines, or a region within a given cloud. + * + * See {@link brooklyn.entity.trait.Startable#start(Collection)}. + * + * Locations may not be {@link Serializable} in subsequent releases! + */ +public interface Location extends Serializable, BrooklynObject { + + /** + * A unique id for this location. + */ + @Override + String getId(); + + /** + * Get the name assigned to this location. + * + * @return the name assigned to the location. + * @since 0.6 (previously getName()) + */ + @Override + String getDisplayName(); + + /** + * Get the 'parent' of this location. Locations are organized into a tree hierarchy, and this method will return a reference + * to the parent of this location, or {@code null} if this location is the tree root. + * + * @return a reference to the parent of this location, or {@code null} if this location is the tree root. + * @since 0.6 (previously getParentLocation()) + */ + Location getParent(); + + /** + * Get the 'children' of this location. Locations are organized into a tree hierarchy, and this method will return a + * collection containing the children of this location. This collection is an unmodifiable view of the data. + * + * @return a collection containing the children of this location. + * @since 0.6 (previously getChildLocations()) + */ + Collection<Location> getChildren(); + + /** + * Set the 'parent' of this location. If this location was previously a child of a different location, it is removed from + * the other location first. It is valid to pass in {@code null} to indicate that the location should be disconnected + * from its parent. + * + * Adds this location as a child of the new parent (see {@code getChildLocations()}). + * + * @param newParent the new parent location object, or {@code null} to clear the parent reference. + * @since 0.6 (previously setParentLocation(Location)) + */ + void setParent(Location newParent); + + /** + * @return meta-data about the location (usually a long line, or a small number of lines). + * + * @since 0.6 + */ + String toVerboseString(); + + /** + * Answers true if this location equals or is an ancestor of the given location. + */ + boolean containsLocation(Location potentialDescendent); + + /** + * Returns configuration set at this location or inherited or default. + * + * Convenience method for {@code config().get(key)} + */ + <T> T getConfig(ConfigKey<T> key); + + /** + * Convenience method for {@code config().get(key)} + * + * @see {@link #getConfig(ConfigKey)} + */ + <T> T getConfig(HasConfigKey<T> key); + + /** + * True iff the indication config key is set, either inherited (second argument true) or locally-only (second argument false). + * + * @deprecated since 0.7.0; use {@link #config()}, such as {@code ((LocationInternal)location).config().getRaw(key).isPresent()} + */ + @Deprecated + boolean hasConfig(ConfigKey<?> key, boolean includeInherited); + + /** + * Returns all config set, either inherited (argument true) or locally-only (argument false). + * + * @deprecated since 0.7.0; use {@link #config()}, such as {@code policy.config().getBag()} + */ + @Deprecated + public Map<String,Object> getAllConfig(boolean includeInherited); + + /** + * Whether this location has support for the given extension type. + * See additional comments in {@link #getExtension(Class)}. + * + * @throws NullPointerException if extensionType is null + */ + boolean hasExtension(Class<?> extensionType); + + /** + * Returns an extension of the given type. Note that the type must be an exact match for + * how the extension was registered (e.g. {@code getExtension(Object.class)} will not match + * anything, even though registered extension extend {@link Object}. + * <p> + * This will not look at extensions of {@link #getParent()}. + * + * @throws IllegalArgumentException if this location does not support the given extension type + * @throws NullPointerException if extensionType is null + */ + <T> T getExtension(Class<T> extensionType); +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/LocationDefinition.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/LocationDefinition.java b/api/src/main/java/org/apache/brooklyn/location/LocationDefinition.java new file mode 100644 index 0000000..3dd58f6 --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/LocationDefinition.java @@ -0,0 +1,42 @@ +/* + * 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.location; + +import java.util.Map; + +import org.apache.brooklyn.api.management.ManagementContext; + +/** + * Defines a location, where the {@link #getSpec()} is like a serialized representation + * of the location so that Brooklyn can create a corresponding location. + * + * Examples include a complete description (e.g. giving a list of machines in a pool), or + * a name that matches a named location defined in the brooklyn poperties. + * + * Users are not expected to implement this, or to use the interface directly. See + * {@link LocationRegistry#resolve(String)} and {@link ManagementContext#getLocationRegistry()}. + */ +public interface LocationDefinition { + + public String getId(); + public String getName(); + public String getSpec(); + public Map<String,Object> getConfig(); + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/LocationNotAvailableException.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/LocationNotAvailableException.java b/api/src/main/java/org/apache/brooklyn/location/LocationNotAvailableException.java new file mode 100644 index 0000000..543fb36 --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/LocationNotAvailableException.java @@ -0,0 +1,35 @@ +/* + * 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.location; + + +/** + * Indicates that a {@link ProvisioningLocation} is not able to provision a requested location + */ +public class LocationNotAvailableException extends Exception { + private static final long serialVersionUID = 1079817235289265761L; + + public LocationNotAvailableException(String s) { + super(s); + } + + public LocationNotAvailableException(String s, Throwable throwable) { + super(s, throwable); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/LocationRegistry.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/LocationRegistry.java b/api/src/main/java/org/apache/brooklyn/location/LocationRegistry.java new file mode 100644 index 0000000..83096d1 --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/LocationRegistry.java @@ -0,0 +1,128 @@ +/* + * 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.location; + +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; + +import javax.annotation.Nullable; + +import brooklyn.util.guava.Maybe; + +import com.google.common.annotations.Beta; + +/** + * The registry of the sorts of locations that brooklyn knows about. Given a + * {@LocationDefinition} or a {@link String} representation of a spec, this can + * be used to create a {@link Location} instance. + */ +@SuppressWarnings("rawtypes") +public interface LocationRegistry { + + /** map of ID (possibly randomly generated) to the definition (spec, name, id, and props; + * where spec is the spec as defined, for instance possibly another named:xxx location) */ + public Map<String,LocationDefinition> getDefinedLocations(); + + /** returns a LocationDefinition given its ID (usually a random string), or null if none */ + public LocationDefinition getDefinedLocationById(String id); + + /** returns a LocationDefinition given its name (e.g. for named locations, supply the bit after the "named:" prefix), + * or null if none */ + public LocationDefinition getDefinedLocationByName(String name); + + /** adds or updates the given defined location */ + public void updateDefinedLocation(LocationDefinition l); + + /** removes the defined location from the registry (applications running there are unaffected) */ + public void removeDefinedLocation(String id); + + /** Returns a fully populated (config etc) location from the given definition, with optional add'l flags. + * the location will be managed by default, unless the manage parameter is false, + * or the manage parameter is null and the CREATE_UNMANAGED flag is set. + * <p> + * The manage parameter is {@link Boolean} so that null can be used to say rely on anything in the flags. + * + * @since 0.7.0, but beta and likely to change as the semantics of this class are tuned */ + @Beta + public Maybe<Location> resolve(LocationDefinition ld, Boolean manage, Map locationFlags); + + /** As {@link #resolve(LocationDefinition, Boolean, Map), with the location managed, and no additional flags, + * unwrapping the result (throwing if not resolvable) */ + public Location resolve(LocationDefinition l); + + /** Returns a location created from the given spec, which might correspond to a definition, or created on-the-fly. + * Optional flags can be passed through to underlying the location. + * @since 0.7.0, but beta and likely to change as the semantics of this class are tuned */ + @Beta + public Maybe<Location> resolve(String spec, Boolean manage, Map locationFlags); + + /** efficiently returns for inspection only a fully populated (config etc) location from the given definition; + * the value might be unmanaged so it is not meant for any use other than inspection, + * but callers should prefer this when they don't wish to create a new location which will be managed in perpetuity! + * + * @deprecated since 0.7.0, use {@link #resolve(LocationDefinition, Boolean, Map)} */ + @Deprecated + public Location resolveForPeeking(LocationDefinition l); + + /** returns fully populated (config etc) location from the given definition, with overrides; + * @deprecated since 0.7.0, use {@link #resolve(LocationDefinition, Boolean, Map)} */ + @Deprecated + public Location resolve(LocationDefinition l, Map<?,?> locationFlags); + + /** See {@link #resolve(String, Boolean, Map)}; asks for the location to be managed, and supplies no additional flags, + * and unwraps the result (throwing if the spec cannot be resolve) */ + public Location resolve(String spec); + + /** Returns true/false depending whether spec seems like a valid location, + * that is it has a chance of being resolved (depending on the spec) but NOT guaranteed, + * as it is not passed to the spec; + * see {@link #resolve(String, Boolean, Map)} which has stronger guarantees + * @deprecated since 0.7.0, not really needed, and semantics are weak; use {@link #resolve(String, Boolean, Map)} */ + @Deprecated + public boolean canMaybeResolve(String spec); + + /** As {@link #resolve(String, Boolean, Map)}, but unwrapped + * @throws NoSuchElementException if the spec cannot be resolved */ + public Location resolve(String spec, @Nullable Map locationFlags); + + /** as {@link #resolve(String)} but returning null (never throwing) + * @deprecated since 0.7.0 use {@link #resolve(String, Boolean, Map)} */ + @Deprecated + public Location resolveIfPossible(String spec); + + /** + * As {@link #resolve(String)} but takes collections (of strings or locations) + * <p> + * Expects a collection of elements being individual location spec strings or locations, + * and returns a list of resolved (newly created and managed) locations. + * <p> + * From 0.7.0 this no longer flattens lists (nested lists are disallowed) + * or parses comma-separated elements (they are resolved as-is) + */ + public List<Location> resolve(Iterable<?> spec); + + /** Takes a string, interpreted as a comma-separated (or JSON style, when you need internal double quotes or commas) list; + * or a list, passed to {@link #resolve(Iterable)}; or null/empty (empty list), + * and returns a list of resolved (created and managed) locations */ + public List<Location> resolveList(Object specList); + + public Map getProperties(); + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/LocationResolver.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/LocationResolver.java b/api/src/main/java/org/apache/brooklyn/location/LocationResolver.java new file mode 100644 index 0000000..1b9bd18 --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/LocationResolver.java @@ -0,0 +1,57 @@ +/* + * 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.location; + +import java.util.Map; + +import org.apache.brooklyn.api.management.ManagementContext; + +import com.google.common.annotations.Beta; + +/** + * Provides a way of creating location instances of a particular type. + */ +public interface LocationResolver { + + void init(ManagementContext managementContext); + + /** the prefix that this resolver will attend to */ + String getPrefix(); + + /** whether the spec is something which should be passed to this resolver */ + boolean accepts(String spec, LocationRegistry registry); + + /** + * Similar to {@link #newLocationFromString(Map, String)} + * but passing in a reference to the registry itself (from which the base properties are discovered) + * and including flags (e.g. user, key, cloud credential) which are known to be for this location. + * <p> + * introduced to support locations which refer to other locations, e.g. NamedLocationResolver + **/ + @SuppressWarnings("rawtypes") + Location newLocationFromString(Map locationFlags, String spec, LocationRegistry registry); + + /** @since 0.7.0 exploring this as a mechanism to disable locations */ + @Beta + public interface EnableableLocationResolver extends LocationResolver { + /** whether the location is enabled */ + boolean isEnabled(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/LocationSpec.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/LocationSpec.java b/api/src/main/java/org/apache/brooklyn/location/LocationSpec.java new file mode 100644 index 0000000..6713cb7 --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/LocationSpec.java @@ -0,0 +1,229 @@ +/* + * 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.location; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Collections; +import java.util.Map; + +import org.apache.brooklyn.api.basic.AbstractBrooklynObjectSpec; +import org.apache.brooklyn.api.management.Task; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import brooklyn.config.ConfigKey; +import brooklyn.config.ConfigKey.HasConfigKey; + +import com.google.common.collect.Maps; + +/** + * Gives details of a location to be created. It describes the location's configuration, and is + * reusable to create multiple locations with the same configuration. + * + * To create a LocationSpec, it is strongly encouraged to use {@code create(...)} methods. + * + * @param <T> The type of location to be created + * + * @author aled + */ +public class LocationSpec<T extends Location> extends AbstractBrooklynObjectSpec<T,LocationSpec<T>> { + + // TODO Would like to add `configure(ConfigBag)`, but `ConfigBag` is in core rather than api + + private static final Logger log = LoggerFactory.getLogger(LocationSpec.class); + + private final static long serialVersionUID = 1L; + + /** + * Creates a new {@link LocationSpec} instance for a location of the given type. The returned + * {@link LocationSpec} can then be customized. + * + * @param type A {@link Location} class + */ + public static <T extends Location> LocationSpec<T> create(Class<T> type) { + return new LocationSpec<T>(type); + } + + /** + * Creates a new {@link LocationSpec} instance with the given config, for a location of the given type. + * + * This is primarily for groovy code; equivalent to {@code LocationSpec.create(type).configure(config)}. + * + * @param config The spec's configuration (see {@link LocationSpec#configure(Map)}). + * @param type A {@link Location} class + */ + public static <T extends Location> LocationSpec<T> create(Map<?,?> config, Class<T> type) { + return LocationSpec.create(type).configure(config); + } + + /** + * Copies entity spec so its configuration can be overridden without modifying the + * original entity spec. + */ + public static <T extends Location> LocationSpec<T> create(LocationSpec<T> spec) { + // need this to get LocationSpec<T> rather than LocationSpec<? extends T> + @SuppressWarnings("unchecked") + Class<T> exactType = (Class<T>)spec.getType(); + + LocationSpec<T> result = create(exactType) + .displayName(spec.getDisplayName()) + .tags(spec.getTags()) + .configure(spec.getConfig()) + .configure(spec.getFlags()) + .catalogItemId(spec.getCatalogItemId()) + .extensions(spec.getExtensions()); + + if (spec.getParent() != null) result.parent(spec.getParent()); + + return (LocationSpec<T>) result; + } + + private String id; + private Location parent; + private final Map<String, Object> flags = Maps.newLinkedHashMap(); + private final Map<ConfigKey<?>, Object> config = Maps.newLinkedHashMap(); + private final Map<Class<?>, Object> extensions = Maps.newLinkedHashMap(); + + protected LocationSpec(Class<T> type) { + super(type); + } + + protected void checkValidType(Class<? extends T> type) { + checkIsImplementation(type, Location.class); + checkIsNewStyleImplementation(type); + } + + /** + * @deprecated since 0.7.0; instead let the management context pick a random+unique id + */ + @Deprecated + public LocationSpec<T> id(String val) { + id = val; + return this; + } + + public LocationSpec<T> parent(Location val) { + parent = checkNotNull(val, "parent"); + return this; + } + + public LocationSpec<T> configure(Map<?,?> val) { + for (Map.Entry<?, ?> entry: val.entrySet()) { + if (entry.getKey()==null) throw new NullPointerException("Null key not permitted"); + if (entry.getKey() instanceof CharSequence) + flags.put(entry.getKey().toString(), entry.getValue()); + else if (entry.getKey() instanceof ConfigKey<?>) + config.put((ConfigKey<?>)entry.getKey(), entry.getValue()); + else if (entry.getKey() instanceof HasConfigKey<?>) + config.put(((HasConfigKey<?>)entry.getKey()).getConfigKey(), entry.getValue()); + else { + log.warn("Spec "+this+" ignoring unknown config key "+entry.getKey()); + } + } + return this; + } + + public LocationSpec<T> configure(CharSequence key, Object val) { + flags.put(checkNotNull(key, "key").toString(), val); + return this; + } + + public <V> LocationSpec<T> configure(ConfigKey<V> key, V val) { + config.put(checkNotNull(key, "key"), val); + return this; + } + + public <V> LocationSpec<T> configureIfNotNull(ConfigKey<V> key, V val) { + return (val != null) ? configure(key, val) : this; + } + + public <V> LocationSpec<T> configure(ConfigKey<V> key, Task<? extends V> val) { + config.put(checkNotNull(key, "key"), val); + return this; + } + + public <V> LocationSpec<T> configure(HasConfigKey<V> key, V val) { + config.put(checkNotNull(key, "key").getConfigKey(), val); + return this; + } + + public <V> LocationSpec<T> configure(HasConfigKey<V> key, Task<? extends V> val) { + config.put(checkNotNull(key, "key").getConfigKey(), val); + return this; + } + + public <V> LocationSpec<T> removeConfig(ConfigKey<V> key) { + config.remove( checkNotNull(key, "key") ); + return this; + } + + public <E> LocationSpec<T> extension(Class<E> extensionType, E extension) { + extensions.put(checkNotNull(extensionType, "extensionType"), checkNotNull(extension, "extension")); + return this; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public <E> LocationSpec<T> extensions(Map<Class<?>, ?> extensions) { + for (Map.Entry<Class<?>, ?> entry : extensions.entrySet()) { + extension((Class)entry.getKey(), entry.getValue()); + } + return this; + } + + /** + * @return The id of the location to be created, or null if brooklyn can auto-generate an id + * + * @deprecated since 0.7.0; instead let the management context pick a random+unique id + */ + @Deprecated + public String getId() { + return id; + } + + /** + * @return The location's parent + */ + public Location getParent() { + return parent; + } + + /** + * @return Read-only construction flags + * @see SetFromFlag declarations on the location type + */ + public Map<String, ?> getFlags() { + return Collections.unmodifiableMap(flags); + } + + /** + * @return Read-only configuration values + */ + public Map<ConfigKey<?>, Object> getConfig() { + return Collections.unmodifiableMap(config); + } + + /** + * @return Read-only extension values + */ + public Map<Class<?>, Object> getExtensions() { + return Collections.unmodifiableMap(extensions); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/LocationType.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/LocationType.java b/api/src/main/java/org/apache/brooklyn/location/LocationType.java new file mode 100644 index 0000000..d7b52ed --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/LocationType.java @@ -0,0 +1,32 @@ +/* + * 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.location; + +import org.apache.brooklyn.api.basic.BrooklynType; + +import com.google.common.annotations.Beta; + +/** + * Gives type information for a {@link Location}. It is immutable. + + * @since 0.7.0 + */ +@Beta +public interface LocationType extends BrooklynType { +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/MachineDetails.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/MachineDetails.java b/api/src/main/java/org/apache/brooklyn/location/MachineDetails.java new file mode 100644 index 0000000..c72d6d9 --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/MachineDetails.java @@ -0,0 +1,34 @@ +/* + * 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.location; + +import javax.annotation.Nonnull; + +/** + * @since 0.7.0 + */ +public interface MachineDetails { + + @Nonnull + HardwareDetails getHardwareDetails(); + + @Nonnull + OsDetails getOsDetails(); + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/MachineLocation.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/MachineLocation.java b/api/src/main/java/org/apache/brooklyn/location/MachineLocation.java new file mode 100644 index 0000000..aef8d04 --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/MachineLocation.java @@ -0,0 +1,46 @@ +/* + * 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.location; + +import java.net.InetAddress; + +import brooklyn.util.net.HasNetworkAddresses; + +/** + * A location that is a machine. + * + * This interface marks a {@link Location} being a network node with an IP address, + * and supports appropriate operations on the node. + */ +public interface MachineLocation extends AddressableLocation, HasNetworkAddresses { + /** + * @return the machine's network address. + */ + InetAddress getAddress(); + + /** @deprecated since 0.7.0. Use getMachineDetails().getOsDetails() instead. */ + @Deprecated + OsDetails getOsDetails(); + + /* + * @return hardware and operating system-specific details for the machine. + */ + MachineDetails getMachineDetails(); + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/MachineLocationCustomizer.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/MachineLocationCustomizer.java b/api/src/main/java/org/apache/brooklyn/location/MachineLocationCustomizer.java new file mode 100644 index 0000000..1c81896 --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/MachineLocationCustomizer.java @@ -0,0 +1,42 @@ +/* + * 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.location; + +import com.google.common.annotations.Beta; + +/** + * Customization hooks to allow apps to perform specific customisation of obtained machines. + * <p> + * Users are strongly encouraged to sub-class {@link BasicMachineLocationCustomizer}, to give + * some protection against this {@link Beta} API changing in future releases. + */ +@Beta +public interface MachineLocationCustomizer { + + /** + * Override to configure the given machine once it has been created (prior to any use). + */ + void customize(MachineLocation machine); + + /** + * Override to handle machine-related cleanup prior to {@link MachineProvisioningLocation} + * releasing the machine. + */ + void preRelease(MachineLocation machine); +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/api/src/main/java/org/apache/brooklyn/location/MachineManagementMixins.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/brooklyn/location/MachineManagementMixins.java b/api/src/main/java/org/apache/brooklyn/location/MachineManagementMixins.java new file mode 100644 index 0000000..7e0de8a --- /dev/null +++ b/api/src/main/java/org/apache/brooklyn/location/MachineManagementMixins.java @@ -0,0 +1,92 @@ +/* + * 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.location; + +import java.util.Map; + +import com.google.common.annotations.Beta; + +/** + * Defines mixins for interesting locations. + */ +public class MachineManagementMixins { + + public interface RichMachineProvisioningLocation<T extends MachineLocation> extends + MachineProvisioningLocation<T>, ListsMachines, GivesMachineMetadata, KillsMachines {} + + public interface ListsMachines { + /** + * @return A map of machine ID to metadata record for all machines known in a given cloud location. + */ + Map<String,MachineMetadata> listMachines(); + } + + public interface GivesMachineMetadata { + /** + * @return the {@link MachineMetadata} for a given (brooklyn) machine location instance, + * or null if not matched. + */ + MachineMetadata getMachineMetadata(MachineLocation location); + } + + public interface KillsMachines { + /** Kills the indicated machine; throws if not recognised or possible */ + void killMachine(MachineLocation machine); + + /** Kills the machine indicated by the given (server-side) machine id; + * note, the ID is the _cloud-service_ ID, + * that is, pass in getMetadata(machineLocation).getId() not the machineLocation.getId() */ + void killMachine(String cloudServiceId); + } + + /** very lightweight machine record */ + public interface MachineMetadata { + /** The cloud service ID -- distinct from any Brooklyn {@link Location#getId()} */ + String getId(); + String getName(); + String getPrimaryIp(); + Boolean isRunning(); + /** original metadata object, if available; e.g. ComputeMetadata when using jclouds */ + Object getOriginalMetadata(); + } + + /** + * Implement to indicate that a location can suspend and resume machines. + */ + @Beta + public interface SuspendResumeLocation extends SuspendsMachines, ResumesMachines {}; + + + @Beta + public interface SuspendsMachines { + /** + * Suspend the indicated machine. + */ + void suspendMachine(MachineLocation location); + } + + @Beta + public interface ResumesMachines { + /** + * Resume the indicated machine. + */ + void resumeMachine(MachineLocation location); + } + +} \ No newline at end of file
