brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From geomacy <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request: Add Karaf equivalents of cloud comma...
Date Thu, 12 May 2016 09:38:27 GMT
Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/131#discussion_r62991551
  
    --- Diff: launcher-common/src/main/java/org/apache/brooklyn/launcher/command/support/CloudExplorerSupport.java
---
    @@ -0,0 +1,437 @@
    +/*
    + * 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.launcher.command.support;
    +
    +import com.google.common.annotations.VisibleForTesting;
    +import com.google.common.base.Objects;
    +import com.google.common.collect.Lists;
    +import org.apache.brooklyn.api.location.Location;
    +import org.apache.brooklyn.api.location.LocationDefinition;
    +import org.apache.brooklyn.api.mgmt.ManagementContext;
    +import org.apache.brooklyn.core.location.LocationConfigKeys;
    +import org.apache.brooklyn.core.location.cloud.CloudLocationConfig;
    +import org.apache.brooklyn.location.jclouds.JcloudsLocation;
    +import org.apache.brooklyn.location.jclouds.JcloudsUtil;
    +import org.apache.brooklyn.util.exceptions.FatalConfigurationRuntimeException;
    +import org.apache.brooklyn.util.stream.Streams;
    +import org.jclouds.blobstore.BlobStore;
    +import org.jclouds.blobstore.BlobStoreContext;
    +import org.jclouds.blobstore.domain.Blob;
    +import org.jclouds.blobstore.domain.StorageMetadata;
    +import org.jclouds.compute.ComputeService;
    +import org.jclouds.compute.domain.ComputeMetadata;
    +import org.jclouds.compute.domain.Hardware;
    +import org.jclouds.compute.domain.Image;
    +import org.jclouds.compute.domain.NodeMetadata;
    +import org.jclouds.compute.domain.Template;
    +import org.jclouds.compute.options.TemplateOptions;
    +
    +import java.io.InputStream;
    +import java.io.PrintStream;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.concurrent.Callable;
    +
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +/**
    + * Convenience for listing Cloud Compute and BlobStore details.
    + * <p>
    + * For fuller functionality, consider instead the jclouds CLI or Ruby Fog CLI.
    + * <p>
    + * The advantage of this utility is that it piggie-backs off the {@code brooklyn.property}
credentials,
    + * so requires less additional credential configuration. It also gives brooklyn-specific
information,
    + * such as which image will be used by default in a given cloud.
    + */
    +public abstract class CloudExplorerSupport implements Callable<Void> {
    +
    +    private ManagementContext managementContext;
    +
    +    public static final String ALL_LOCATIONS_DESC =
    +        "All locations (i.e. all locations in brooklyn.properties for which there are
credentials)";
    +    public boolean allLocations;
    +
    +    public static final String LOCATION_DESC =
    +        "A location spec (e.g. referring to a named location in brooklyn.properties file)";
    +    public String location;
    +
    +    public static final String AUTOCONFIRM_DESC = "Automatically answer yes to any questions";
    +    public boolean autoconfirm = false;
    +
    +
    +    @VisibleForTesting
    +    protected PrintStream stdout = System.out;
    +
    +    @VisibleForTesting
    +    protected PrintStream stderr = System.err;
    +
    +    @VisibleForTesting
    +    protected InputStream stdin = System.in;
    +
    +    public CloudExplorerSupport(ManagementContext managementContext, boolean allLocations,
String location, boolean autoconfirm) {
    +        this.managementContext = managementContext;
    +        this.allLocations = allLocations;
    +        this.location = location;
    +        this.autoconfirm = autoconfirm;
    +    }
    +
    +    protected abstract void doCall(JcloudsLocation loc, String indent) throws Exception;
    +
    +    @Override
    +    public Void call() throws Exception {
    +        List<JcloudsLocation> locs = Lists.newArrayList();
    +        if (location != null && allLocations) {
    +            throw new FatalConfigurationRuntimeException("Must not specify --location
and --all-locations");
    +        } else if (location != null) {
    +            JcloudsLocation loc = (JcloudsLocation) managementContext.getLocationRegistry().getLocationManaged(location);
    +            locs.add(loc);
    +        } else if (allLocations) {
    +            // Find all named locations that point at different target clouds
    +            Map<String, LocationDefinition> definedLocations = managementContext.getLocationRegistry().getDefinedLocations();
    +            for (LocationDefinition locationDef : definedLocations.values()) {
    +
    +                Location loc = managementContext.getLocationManager().createLocation(
    +                    managementContext.getLocationRegistry().getLocationSpec(locationDef).get()
);
    +
    +                if (loc instanceof JcloudsLocation) {
    +                    boolean found = false;
    +                    for (JcloudsLocation existing : locs) {
    +                        if (equalTargets(existing, (JcloudsLocation) loc)) {
    +                            found = true;
    +                            break;
    +                        }
    +                    }
    +                    if (!found) {
    +                        locs.add((JcloudsLocation) loc);
    +                    }
    +                }
    +            }
    +        } else {
    +            throw new FatalConfigurationRuntimeException("Must specify one of --location
or --all-locations");
    +        }
    +
    +        for (JcloudsLocation loc : locs) {
    +            stdout.println("Location {");
    +            stdout.println("\tprovider: "+loc.getProvider());
    +            stdout.println("\tdisplayName: "+loc.getDisplayName());
    +            stdout.println("\tidentity: "+loc.getIdentity());
    +            if (loc.getEndpoint() != null) stdout.println("\tendpoint: "+loc.getEndpoint());
    +            if (loc.getRegion() != null) stdout.println("\tregion: "+loc.getRegion());
    +
    +            try {
    +                doCall(loc, "\t");
    +            } finally {
    +                stdout.println("}");
    +            }
    +        }
    --- End diff --
    
    I've added a TODO note to consider doing this, it's a good idea.  I don't think it needs
done as part of this PR.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message