Search in sources :

Example 86 with Result

use of io.fabric8.insight.metrics.model.Result in project fabric8 by fabric8io.

the class Controller method applyOAuthClient.

public void applyOAuthClient(OAuthClient entity, String sourceName) {
    OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
    if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.OAUTH)) {
        if (supportOAuthClients) {
            String id = getName(entity);
            Objects.notNull(id, "No name for " + entity + " " + sourceName);
            if (isServicesOnlyMode()) {
                LOG.debug("Only processing Services right now so ignoring OAuthClient: " + id);
                return;
            }
            OAuthClient old = openShiftClient.oAuthClients().withName(id).get();
            if (isRunning(old)) {
                if (isIgnoreRunningOAuthClients()) {
                    LOG.info("Not updating the OAuthClient which are shared across namespaces as its already running");
                    return;
                }
                if (UserConfigurationCompare.configEqual(entity, old)) {
                    LOG.info("OAuthClient has not changed so not doing anything");
                } else {
                    if (isRecreateMode()) {
                        openShiftClient.oAuthClients().withName(id).delete();
                        doCreateOAuthClient(entity, sourceName);
                    } else {
                        try {
                            Object answer = openShiftClient.oAuthClients().withName(id).replace(entity);
                            LOG.info("Updated OAuthClient result: " + answer);
                        } catch (Exception e) {
                            onApplyError("Failed to update OAuthClient from " + sourceName + ". " + e + ". " + entity, e);
                        }
                    }
                }
            } else {
                if (!isAllowCreate()) {
                    LOG.warn("Creation disabled so not creating an OAuthClient from " + sourceName + " name " + getName(entity));
                } else {
                    doCreateOAuthClient(entity, sourceName);
                }
            }
        }
    }
}
Also used : OAuthClient(io.fabric8.openshift.api.model.OAuthClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) JSONObject(org.json.JSONObject) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) FileNotFoundException(java.io.FileNotFoundException) OpenShiftNotAvailableException(io.fabric8.openshift.client.OpenShiftNotAvailableException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 87 with Result

use of io.fabric8.insight.metrics.model.Result in project fabric8 by fabric8io.

the class Controller method applyPod.

public void applyPod(Pod pod, String sourceName) throws Exception {
    String namespace = getNamespace();
    String id = getName(pod);
    Objects.notNull(id, "No name for " + pod + " " + sourceName);
    if (isServicesOnlyMode()) {
        LOG.debug("Only processing Services right now so ignoring Pod: " + namespace + ":" + id);
        return;
    }
    Pod old = kubernetesClient.pods().inNamespace(namespace).withName(id).get();
    if (isRunning(old)) {
        if (UserConfigurationCompare.configEqual(pod, old)) {
            LOG.info("Pod has not changed so not doing anything");
        } else {
            if (isRecreateMode()) {
                LOG.info("Deleting Pod: " + id);
                kubernetesClient.pods().inNamespace(namespace).withName(id).delete();
                doCreatePod(pod, namespace, sourceName);
            } else {
                LOG.info("Updating a Pod from " + sourceName + " namespace " + namespace + " name " + getName(pod));
                try {
                    Object answer = kubernetesClient.pods().inNamespace(namespace).withName(id).replace(pod);
                    LOG.info("Updated Pod result: " + answer);
                } catch (Exception e) {
                    onApplyError("Failed to update Pod from " + sourceName + ". " + e + ". " + pod, e);
                }
            }
        }
    } else {
        if (!isAllowCreate()) {
            LOG.warn("Creation disabled so not creating a pod from " + sourceName + " namespace " + namespace + " name " + getName(pod));
        } else {
            doCreatePod(pod, namespace, sourceName);
        }
    }
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) JSONObject(org.json.JSONObject) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) FileNotFoundException(java.io.FileNotFoundException) OpenShiftNotAvailableException(io.fabric8.openshift.client.OpenShiftNotAvailableException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 88 with Result

use of io.fabric8.insight.metrics.model.Result in project fabric8 by fabric8io.

the class ApmAgent method initialize.

/**
 * @return false if already initialized, else true if is actually initialized
 */
public boolean initialize(final Instrumentation instrumentation, String args) throws Exception {
    boolean result;
    if ((result = initialized.compareAndSet(false, true))) {
        this.instrumentation = instrumentation;
        PropertyUtils.setProperties(configuration, args);
        configuration.addChangeListener(this);
        apmAgentContext.initialize();
        ApmConfiguration.STRATEGY theStrategy = configuration.getStrategyImpl();
        switch(theStrategy) {
            case TRACE:
                this.strategy = new TraceStrategy(apmAgentContext, instrumentation);
                LOG.debug("Using Trace strategy");
                break;
            default:
                this.strategy = new SamplingStrategy(apmAgentContext);
                LOG.debug("Using Sampling strategy");
        }
        this.strategy.initialize();
        // add shutdown hook
        Thread cleanup = new Thread() {

            @Override
            public void run() {
                try {
                    ApmAgent apmAgent = ApmAgent.INSTANCE;
                    apmAgent.shutDown();
                } catch (Exception e) {
                    LOG.warn("Failed to run shutdown hook due " + e.getMessage(), e);
                }
            }
        };
        Runtime.getRuntime().addShutdownHook(cleanup);
    }
    return result;
}
Also used : TraceStrategy(io.fabric8.apmagent.strategy.trace.TraceStrategy) SamplingStrategy(io.fabric8.apmagent.strategy.sampling.SamplingStrategy)

Example 89 with Result

use of io.fabric8.insight.metrics.model.Result in project fabric8 by fabric8io.

the class ApmAgentContext method buildDeltaList.

public List<ClassInfo> buildDeltaList() {
    List<ClassInfo> result = new ArrayList<>();
    for (ClassInfo classInfo : allMethods.values()) {
        if (classInfo.isTransformed()) {
            // check to see its still should be audited
            if (configuration.isAudit(classInfo.getClassName())) {
                boolean retransform = false;
                // check to see if there's a change to methods that should be transformed
                Set<String> transformedMethodNames = classInfo.getAllTransformedMethodNames();
                for (String methodName : transformedMethodNames) {
                    if (!configuration.isAudit(classInfo.getClassName(), methodName)) {
                        retransform = true;
                        break;
                    }
                }
                if (!retransform) {
                    // check to see if there are methods that should now be audited but weren't
                    Set<String> allMethodNames = classInfo.getAllMethodNames();
                    for (String methodName : allMethodNames) {
                        if (!transformedMethodNames.contains(methodName) && configuration.isAudit(classInfo.getClassName(), methodName)) {
                            retransform = true;
                            break;
                        }
                    }
                }
                if (retransform) {
                    result.add(classInfo);
                }
            } else {
                // we were once audited - but now need to be removed
                result.add(classInfo);
            }
        } else if (configuration.isAudit(classInfo.getClassName())) {
            if (classInfo.isCanTransform()) {
                result.add(classInfo);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ClassInfo(io.fabric8.apmagent.ClassInfo)

Example 90 with Result

use of io.fabric8.insight.metrics.model.Result in project fabric8 by fabric8io.

the class NoNamespaceTest method testServiceInjection.

@Test
public void testServiceInjection() {
    KubernetesClient client = new DefaultKubernetesClient();
    String namespace = client.getNamespace();
    // If namespace not null or empty then don't fail if the result is unexpected.
    Assume.assumeTrue(Strings.isNullOrBlank(namespace));
    expectedException.expect(ThrowableMessageMatcher.hasMessage(CoreMatchers.equalTo("No kubernetes service could be found for name: notfound in namespace: null")));
    createInstance(MyBean.class);
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)104 Expectations (mockit.Expectations)49 HashMap (java.util.HashMap)32 Map (java.util.Map)24 ArrayList (java.util.ArrayList)23 File (java.io.File)21 GitContext (io.fabric8.api.GitContext)20 IOException (java.io.IOException)20 Exchange (org.apache.camel.Exchange)20 Processor (org.apache.camel.Processor)20 DefaultPullPushPolicy (io.fabric8.git.internal.DefaultPullPushPolicy)18 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)17 Probe (io.fabric8.kubernetes.api.model.Probe)16 PatchResult (io.fabric8.patch.management.PatchResult)13 Properties (java.util.Properties)13 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)11 Patch (io.fabric8.patch.management.Patch)11 PatchException (io.fabric8.patch.management.PatchException)11 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)10 TreeMap (java.util.TreeMap)10