Search in sources :

Example 41 with FabricService

use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.

the class MQManager method assignProfileToContainers.

public static void assignProfileToContainers(FabricService fabricService, Profile profile, String[] assignContainers) {
    for (String containerName : assignContainers) {
        try {
            Container container = fabricService.getContainer(containerName);
            if (container == null) {
                LOG.warn("Failed to assign profile to " + containerName + ": profile doesn't exists");
            } else {
                Set<Profile> profiles = new HashSet<Profile>(Arrays.asList(container.getProfiles()));
                profiles.add(profile);
                container.setProfiles(profiles.toArray(new Profile[profiles.size()]));
                LOG.info("Profile successfully assigned to " + containerName);
            }
        } catch (Exception e) {
            LOG.warn("Failed to assign profile to " + containerName + ": " + e.getMessage());
        }
    }
}
Also used : Container(io.fabric8.api.Container) Profile(io.fabric8.api.Profile) MalformedObjectNameException(javax.management.MalformedObjectNameException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 42 with FabricService

use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.

the class CloudFirewallEdit method doExecute.

@Override
protected Object doExecute() throws Exception {
    if (validateArguments()) {
        ComputeService computeService = findTargetComputeService();
        if (computeService == null) {
            return null;
        }
        Set<String> sourceCidrs = collectCirds();
        FirewallManager firewallManager = firewallManagerFactory.getFirewallManager(computeService);
        NodeMetadata node = null;
        if (!Strings.isNullOrEmpty(targetContainerName) && getCurator().getZookeeperClient().isConnected() && fabricService != null) {
            CreateJCloudsContainerMetadata metadata = getContainerCloudMetadata(targetContainerName);
            if (metadata != null && !Strings.isNullOrEmpty(metadata.getNodeId())) {
                targetNodeId = metadata.getNodeId();
            }
        }
        if (!Strings.isNullOrEmpty(targetNodeId)) {
            node = computeService.getNodeMetadata(targetNodeId);
        }
        if (node == null) {
            System.err.println("Could not find target node. Make sure you specified either --target-node-id or --target-container using a valid cloud container.");
            return null;
        }
        if (flush) {
            firewallManager.addRule(Rule.create().destination(node).flush());
            return null;
        }
        for (String cidr : sourceCidrs) {
            Rule rule = Rule.create().destination(node).source(cidr);
            if (port != null && port.length > 0) {
                rule = rule.ports(port);
            }
            if (revoke) {
                firewallManager.addRule(rule.revoke());
            } else {
                firewallManager.addRule(rule);
            }
        }
    }
    return null;
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) FirewallManager(io.fabric8.service.jclouds.firewall.FirewallManager) CreateJCloudsContainerMetadata(io.fabric8.service.jclouds.CreateJCloudsContainerMetadata) Rule(io.fabric8.service.jclouds.firewall.Rule) ComputeService(org.jclouds.compute.ComputeService)

Example 43 with FabricService

use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.

the class DeploymentAgent method updateStatus.

private void updateStatus(String status, Throwable result, boolean force) {
    try {
        FabricService fs;
        if (force) {
            fs = fabricService.waitForService(0);
        } else {
            fs = fabricService.getService();
        }
        updateStatus(fs, status, result, force);
    } catch (Throwable e) {
        LOGGER.warn("Unable to set provisioning result");
    }
}
Also used : FabricService(io.fabric8.api.FabricService)

Example 44 with FabricService

use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.

the class DownloadManagers method createDownloadManager.

/**
 * Creates a DownloadManager
 */
public static DownloadManager createDownloadManager(FabricService fabricService, Profile profile, ScheduledExecutorService executorService) {
    Map<String, String> configuration = profile.getConfiguration(Constants.AGENT_PID);
    if (configuration == null) {
        configuration = new HashMap<>();
    }
    Dictionary<String, String> properties = mapToDictionary(configuration);
    Mirror mirror = AgentUtils.getMavenProxy(fabricService);
    MavenResolver resolver = MavenResolvers.createMavenResolver(mirror, properties, "org.ops4j.pax.url.mvn");
    return createDownloadManager(resolver, executorService);
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) Mirror(org.apache.maven.settings.Mirror)

Example 45 with FabricService

use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.

the class DownloadManagers method createDownloadManager.

/**
 * Creates a download manager using the current container's maven configuration
 */
public static DownloadManager createDownloadManager(FabricService fabricService, ScheduledExecutorService executorService) {
    Profile overlayProfile = fabricService.getCurrentContainer().getOverlayProfile();
    Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
    return createDownloadManager(fabricService, effectiveProfile, executorService);
}
Also used : Profile(io.fabric8.api.Profile)

Aggregations

FabricService (io.fabric8.api.FabricService)80 Container (io.fabric8.api.Container)76 Test (org.junit.Test)52 Profile (io.fabric8.api.Profile)50 BundleContext (org.osgi.framework.BundleContext)29 Version (io.fabric8.api.Version)24 ArrayList (java.util.ArrayList)21 ProfileService (io.fabric8.api.ProfileService)19 HashMap (java.util.HashMap)16 CuratorFramework (org.apache.curator.framework.CuratorFramework)16 HashSet (java.util.HashSet)14 Map (java.util.Map)13 FabricException (io.fabric8.api.FabricException)12 IOException (java.io.IOException)12 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)11 Ignore (org.junit.Ignore)10 File (java.io.File)9 LinkedList (java.util.LinkedList)9 Path (javax.ws.rs.Path)8 FabricRequirements (io.fabric8.api.FabricRequirements)7