Search in sources :

Example 1 with External

use of io.fabric8.annotations.External in project carbon-apimgt by wso2.

the class ServiceDiscovererKubernetesTestCase method testInitWhileExternalTokenFileNameNotGiven.

@Test(description = "Test init method when external service account token file name is NOT given")
public void testInitWhileExternalTokenFileNameNotGiven() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class);
    ServiceDiscovererKubernetes sdKubernetes = new ServiceDiscovererKubernetes();
    sdKubernetes.setClient(openShiftClient);
    try {
        sdKubernetes.initImpl(createImplParametersMap(""));
    } catch (ServiceDiscoveryException e) {
        // since pod's token is then searched, this is exception msg we get
        Assert.assertEquals(e.getCause().getMessage(), "Error while reading file /var/run/secrets/kubernetes.io/serviceaccount/token");
    }
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ServiceDiscoveryException(org.wso2.carbon.apimgt.core.exception.ServiceDiscoveryException) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with External

use of io.fabric8.annotations.External in project docker-maven-plugin by fabric8io.

the class DockerAccessFactory method getDefaultDockerHostProviders.

/**
 * Return a list of providers which could delive connection parameters from
 * calling external commands. For this plugin this is docker-machine, but can be overridden
 * to add other config options, too.
 *
 * @return list of providers or <code>null</code> if none are applicable
 */
private List<DockerConnectionDetector.DockerHostProvider> getDefaultDockerHostProviders(DockerAccessContext dockerAccessContext, Logger log) {
    DockerMachineConfiguration config = dockerAccessContext.getMachine();
    if (dockerAccessContext.isSkipMachine()) {
        config = null;
    } else if (config == null) {
        Properties projectProps = dockerAccessContext.getProjectProperties();
        if (projectProps.containsKey(DockerMachineConfiguration.DOCKER_MACHINE_NAME_PROP)) {
            config = new DockerMachineConfiguration(projectProps.getProperty(DockerMachineConfiguration.DOCKER_MACHINE_NAME_PROP), projectProps.getProperty(DockerMachineConfiguration.DOCKER_MACHINE_AUTO_CREATE_PROP));
        }
    }
    List<DockerConnectionDetector.DockerHostProvider> ret = new ArrayList<>();
    ret.add(new DockerMachine(log, config));
    return ret;
}
Also used : DockerMachine(io.fabric8.maven.docker.access.DockerMachine) DockerMachineConfiguration(io.fabric8.maven.docker.config.DockerMachineConfiguration) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 3 with External

use of io.fabric8.annotations.External in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method gitOperation.

@Override
public <T> T gitOperation(GitContext context, GitOperation<T> gitop, PersonIdent personIdent) {
    IllegalArgumentAssertion.assertNotNull(gitop, "gitop");
    IllegalArgumentAssertion.assertNotNull(context, "context");
    LockHandle writeLock = aquireWriteLock();
    try {
        assertValid();
        LOGGER.debug("External call to execute a git operation: " + gitop);
        return executeInternal(context, personIdent, gitop);
    } finally {
        writeLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle)

Example 4 with External

use of io.fabric8.annotations.External in project fabric8 by jboss-fuse.

the class SubsystemResolveContext method findProviders.

@Override
public List<Capability> findProviders(Requirement requirement) {
    List<Capability> caps = new ArrayList<Capability>();
    Region requirerRegion = getRegion(requirement.getResource());
    if (requirerRegion != null) {
        Map<Requirement, Collection<Capability>> resMap = repository.findProviders(Collections.singleton(requirement));
        Collection<Capability> res = resMap != null ? resMap.get(requirement) : null;
        if (res != null && !res.isEmpty()) {
            caps.addAll(res);
        } else if (globalRepository != null) {
            // Only bring in external resources for non optional requirements
            if (!RESOLUTION_OPTIONAL.equals(requirement.getDirectives().get(RESOLUTION_DIRECTIVE))) {
                resMap = globalRepository.findProviders(Collections.singleton(requirement));
                res = resMap != null ? resMap.get(requirement) : null;
                if (res != null && !res.isEmpty()) {
                    caps.addAll(res);
                }
            }
        }
        // Use the digraph to prune non visible capabilities
        Visitor visitor = new Visitor(caps);
        requirerRegion.visitSubgraph(visitor);
        Collection<Capability> allowed = visitor.getAllowed();
        caps.retainAll(allowed);
        // the parent one
        if (caps.size() > 1) {
            Map<String, Resource> providers = new HashMap<String, Resource>();
            for (Capability cap : caps) {
                Resource resource = cap.getResource();
                String id = getSymbolicName(resource) + "|" + getVersion(resource);
                Resource prev = providers.get(id);
                if (prev != null && prev != resource) {
                    Region r1 = getRegion(prev);
                    Region r2 = getRegion(resource);
                    boolean r2canSeeR1 = isResourceVisibleFromRegion(prev, r2);
                    boolean r1canSeeR2 = isResourceVisibleFromRegion(resource, r1);
                    if (r1canSeeR2 && r2canSeeR1) {
                        // r1 and r2 can see each other
                        int reqDiff = prev.getRequirements(null).size() - resource.getRequirements(null).size();
                        if (reqDiff == 0) {
                            String r1Name = getRegion(prev).getName();
                            String r2Name = getRegion(resource).getName();
                            int c = r1Name.compareTo(r2Name);
                            if (c == 0) {
                                // One of the resource has to be a bundle, use that one
                                c = (prev instanceof BundleRevision) ? -1 : +1;
                            }
                            resource = c < 0 ? prev : resource;
                        } else {
                            // one of the resource has less requirements, so use this one
                            // This can be the case when one resource has conditionals, which adds further
                            // requirements to the condition feature.
                            resource = reqDiff < 0 ? prev : resource;
                        }
                    } else {
                        // only one region can see the other, grab the correct
                        resource = r1canSeeR2 ? prev : resource;
                    }
                }
                providers.put(id, resource);
            }
            for (Iterator<Capability> it = caps.iterator(); it.hasNext(); ) {
                Capability cap = it.next();
                if (!providers.values().contains(cap.getResource())) {
                    it.remove();
                }
            }
        }
        // Sort caps
        Collections.sort(caps, candidateComparator);
    }
    return caps;
}
Also used : HostedCapability(org.osgi.service.resolver.HostedCapability) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) Requirement(org.osgi.resource.Requirement) ResourceUtils.addIdentityRequirement(io.fabric8.agent.resolver.ResourceUtils.addIdentityRequirement) BundleRevision(org.osgi.framework.wiring.BundleRevision) Region(org.eclipse.equinox.region.Region) Collection(java.util.Collection)

Example 5 with External

use of io.fabric8.annotations.External in project fabric8-maven-plugin by fabric8io.

the class ApplyMojo method shouldCreateExternalURLForService.

/**
 * Should we try to create an external URL for the given service?
 * <p/>
 * By default lets ignore the kubernetes services and any service which does not expose ports 80 and 443
 *
 * @return true if we should create an OpenShift Route for this service.
 */
private boolean shouldCreateExternalURLForService(Service service, String id) {
    if ("kubernetes".equals(id) || "kubernetes-ro".equals(id)) {
        return false;
    }
    Set<Integer> ports = KubernetesHelper.getPorts(service);
    log.debug("Service " + id + " has ports: " + ports);
    if (ports.size() == 1) {
        String type = null;
        ServiceSpec spec = service.getSpec();
        if (spec != null) {
            type = spec.getType();
            if (Objects.equals(type, "LoadBalancer")) {
                return true;
            }
        }
        log.info("Not generating route for service " + id + " type is not LoadBalancer: " + type);
        return false;
    } else {
        log.info("Not generating route for service " + id + " as only single port services are supported. Has ports: " + ports);
        return false;
    }
}
Also used : ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) KubernetesHelper.createIntOrString(io.fabric8.kubernetes.api.KubernetesHelper.createIntOrString)

Aggregations

ArrayList (java.util.ArrayList)4 External (io.fabric8.annotations.External)3 PortName (io.fabric8.annotations.PortName)3 Protocol (io.fabric8.annotations.Protocol)3 ServiceName (io.fabric8.annotations.ServiceName)3 LockHandle (io.fabric8.api.LockHandle)3 Alias (io.fabric8.annotations.Alias)2 Configuration (io.fabric8.annotations.Configuration)2 Endpoint (io.fabric8.annotations.Endpoint)2 Path (io.fabric8.annotations.Path)2 Service (io.fabric8.kubernetes.api.model.Service)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)2 IOException (java.io.IOException)2 Type (java.lang.reflect.Type)2 List (java.util.List)2 Set (java.util.Set)2 DeploymentEndpoints (com.liveperson.ephemerals.deploy.DeploymentEndpoints)1 ResourceUtils.addIdentityRequirement (io.fabric8.agent.resolver.ResourceUtils.addIdentityRequirement)1 DataStoreTemplate (io.fabric8.api.DataStoreTemplate)1