Java Code Examples for org.apache.brooklyn.api.location.LocationSpec#configure()

The following examples show how to use org.apache.brooklyn.api.location.LocationSpec#configure() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenShiftLocation.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean findResourceAddress(LocationSpec<? extends KubernetesMachineLocation> locationSpec, Entity entity, HasMetadata metadata, String resourceType, String resourceName, String namespace) {
    if (super.findResourceAddress(locationSpec, entity, metadata, resourceType, resourceName, namespace)) {
        return true;
    }

    if (resourceType.equals(OpenShiftResource.DEPLOYMENT_CONFIG)) {
        DeploymentConfig deploymentConfig = (DeploymentConfig) metadata;
        Map<String, String> labels = deploymentConfig.getSpec().getTemplate().getMetadata().getLabels();
        Pod pod = getPod(namespace, labels);
        entity.sensors().set(OpenShiftPod.KUBERNETES_POD, pod.getMetadata().getName());

        InetAddress node = Networking.getInetAddressWithFixedName(pod.getSpec().getNodeName());
        String podAddress = pod.getStatus().getPodIP();

        locationSpec.configure("address", node);
        locationSpec.configure(SshMachineLocation.PRIVATE_ADDRESSES, ImmutableSet.of(podAddress));

        return true;
    } else {
        return false;
    }
}
 
Example 2
Source File: JcloudsLocationReleasePortForwardingConfiguredDefaultTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Override
protected LocationSpec<JcloudsSshMachineLocation> extraSpecChanges(LocationSpec<JcloudsSshMachineLocation> spec) {
    return spec.configure(JcloudsLocation.PORT_FORWARDING_MANAGER, portForwardManager);
}
 
Example 3
Source File: BasicLocationRegistry.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Override
public Maybe<LocationSpec<? extends Location>> getLocationSpec(String spec, Map locationFlags) {
    try {
        locationFlags = MutableMap.copyOf(locationFlags);
        
        Set<String> seenSoFar = specsSeen.get();
        if (seenSoFar==null) {
            seenSoFar = new LinkedHashSet<String>();
            specsSeen.set(seenSoFar);
        }
        if (seenSoFar.contains(spec))
            return Maybe.absent(Suppliers.ofInstance(new IllegalStateException("Circular reference in definition of location '"+spec+"' ("+seenSoFar+")")));
        seenSoFar.add(spec);
        
        LocationResolver resolver = getSpecResolver(spec);

        if (resolver != null) {
            try {
                LocationSpec<? extends Location> specO = resolver.newLocationSpecFromString(spec, locationFlags, this);
                specO.configure(LocationInternal.ORIGINAL_SPEC, spec);
                specO.configure(LocationInternal.NAMED_SPEC_NAME, spec);
                return (Maybe) Maybe.of(specO);
            } catch (RuntimeException e) {
                 return Maybe.absent(Suppliers.ofInstance(e));
            }
        }

        // problem: but let's ensure that classpath is sane to give better errors in common IDE bogus case;
        // and avoid repeated logging
        String errmsg = "Unknown location '"+spec+"'";
        ConfigBag cfg = ConfigBag.newInstance(locationFlags);
        String orig = cfg.get(LocationInternal.ORIGINAL_SPEC);                
        String named = cfg.get(LocationInternal.NAMED_SPEC_NAME);
        if (Strings.isNonBlank(named) && !named.equals(spec) && !named.equals(orig)) {
            errmsg += " when looking up '"+named+"'";
        }
        if (Strings.isNonBlank(orig) && !orig.equals(spec)) {
            errmsg += " when resolving '"+orig+"'";
        }

        if (spec == null || specsWarnedOnException.add(spec)) {
            if (resolvers.get("id")==null || resolvers.get("named")==null) {
                log.error("Standard location resolvers not installed, location resolution will fail shortly. "
                        + "This usually indicates a classpath problem, such as when running from an IDE which "
                        + "has not properly copied META-INF/services from src/main/resources. "
                        + errmsg+". "
                        + "Known resolvers are: "+resolvers.keySet());
                errmsg = errmsg+": "
                        + "Problem detected with location resolver configuration; "
                        + resolvers.keySet()+" are the only available location resolvers. "
                        + "More information can be found in the logs.";
            } else {
                if (log.isDebugEnabled()) log.debug(errmsg + " (if this is being loaded it will fail shortly): known resolvers are: "+resolvers.keySet());
            }
        } else {
            if (log.isDebugEnabled()) log.debug(errmsg + "(with retry, already warned)");
            errmsg += " (with retry)";
        }

        return Maybe.absent(Suppliers.ofInstance(new NoSuchElementException(errmsg)));

    } finally {
        specsSeen.remove();
    }
}