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);
}
}
}
}
}
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);
}
}
}
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;
}
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;
}
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);
}
Aggregations