removed filters application to extensions
This commit is contained in:
parent
5c80342e8c
commit
e36605ec12
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.smartgears;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContainerInitializer;
|
||||
|
@ -17,10 +19,13 @@ import org.slf4j.LoggerFactory;
|
|||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
|
||||
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
|
||||
import io.micrometer.core.instrument.binder.jvm.JvmInfoMetrics;
|
||||
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
|
||||
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
|
||||
import io.micrometer.core.instrument.binder.logging.LogbackMetrics;
|
||||
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
|
||||
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
|
||||
import io.micrometer.core.instrument.binder.tomcat.TomcatMetrics;
|
||||
import io.micrometer.prometheus.PrometheusConfig;
|
||||
import io.micrometer.prometheus.PrometheusMeterRegistry;
|
||||
|
||||
|
@ -113,6 +118,9 @@ public class Bootstrap implements ServletContainerInitializer {
|
|||
new JvmThreadMetrics().bindTo(registry);
|
||||
new UptimeMetrics().bindTo(registry);
|
||||
new ProcessorMetrics().bindTo(registry);
|
||||
new TomcatMetrics(null, emptyList()).bindTo(registry);
|
||||
new LogbackMetrics().bindTo(registry);
|
||||
new JvmInfoMetrics().bindTo(registry);
|
||||
|
||||
Metrics.addRegistry(registry);
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@ public class ContainerProfileManager extends ContainerHandler {
|
|||
private static final String PUBLISHED_PROP = "published";
|
||||
private List<Publisher> publishers;
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart(ContainerLifecycleEvent.Start e) {
|
||||
|
||||
|
@ -80,13 +79,11 @@ public class ContainerProfileManager extends ContainerHandler {
|
|||
|
||||
}
|
||||
|
||||
|
||||
private void activated(){
|
||||
publishers = context.configuration().mode()!=Mode.offline?
|
||||
ProviderFactory.provider().publishers():
|
||||
Collections.emptyList();
|
||||
registerObservers();
|
||||
schedulePeriodicUpdates();
|
||||
private void activated() {
|
||||
publishers = context.configuration().mode() != Mode.offline ? ProviderFactory.provider().publishers()
|
||||
: Collections.emptyList();
|
||||
registerObservers();
|
||||
schedulePeriodicUpdates();
|
||||
}
|
||||
|
||||
private void registerObservers() {
|
||||
|
@ -94,59 +91,62 @@ public class ContainerProfileManager extends ContainerHandler {
|
|||
@Observes({ activation, part_activation, shutdown, stop, failure })
|
||||
void onChanged(ContainerLifecycle lc) {
|
||||
|
||||
// since we do not know the observers, they will deal with failures and their consequences
|
||||
// since we do not know the observers, they will deal with failures and their
|
||||
// consequences
|
||||
// any that comes back will be logged in this event thread
|
||||
context.events().fire(context, changed);
|
||||
}
|
||||
|
||||
@Observes(value = changed, kind = critical)
|
||||
void publishAfterChange(ContainerContext context) {
|
||||
log.info("Publish after profile Change event called");
|
||||
//if we've failed before first publication do not try to publish
|
||||
//(we may well have failed there)
|
||||
if (!context.properties().contains(PUBLISHED_PROP)) {
|
||||
context.properties().add(new Property(PUBLISHED_PROP, true));
|
||||
log.info("publishing container for the first time");
|
||||
if (context.lifecycle().state() != ContainerState.failed) {
|
||||
publishers.forEach(p -> {
|
||||
log.info("Publish after profile Change event called -- contains published prop? {}",context.properties().contains(PUBLISHED_PROP));
|
||||
// if we've failed before first publication do not try to publish
|
||||
// (we may well have failed there)
|
||||
if (context.lifecycle().state() != ContainerState.failed) {
|
||||
if (!context.properties().contains(PUBLISHED_PROP)) {
|
||||
context.properties().add(new Property(PUBLISHED_PROP, true));
|
||||
log.info("publishing container for the first time");
|
||||
|
||||
publishers.parallelStream().forEach(p -> {
|
||||
try {
|
||||
p.create(context,
|
||||
context.authorizationProvider().getContexts());
|
||||
}catch (Exception e) {
|
||||
log.error("cannot publish container for first time with publisher type {} (see details)", p.getClass().getCanonicalName(), e);
|
||||
p.create(context, context.authorizationProvider().getContexts());
|
||||
} catch (Throwable e) {
|
||||
log.error(
|
||||
"cannot publish container for first time with publisher type {} (see details)",
|
||||
p.getClass().getCanonicalName(), e);
|
||||
}
|
||||
});
|
||||
} else
|
||||
publishers.parallelStream().forEach(p -> {
|
||||
try {
|
||||
p.update(context);
|
||||
} catch (Throwable e) {
|
||||
log.error("cannot publish container with publisher type {} (see details)",
|
||||
p.getClass().getCanonicalName(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
publishers.forEach(p -> {
|
||||
try {
|
||||
p.update(context);
|
||||
}catch (Exception e) {
|
||||
log.error("cannot publish container with publisher type {} (see details)", p.getClass().getCanonicalName(), e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Observes(value = addToContext)
|
||||
void addTo(String scope) {
|
||||
log.info("add_to_context event arrived in container");
|
||||
for (Publisher publisher: publishers)
|
||||
for (Publisher publisher : publishers)
|
||||
try {
|
||||
log.trace("publishing container within new scope");
|
||||
publisher.create(context,
|
||||
Collections.singleton(scope));
|
||||
publisher.create(context, Collections.singleton(scope));
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
log.error("cannot add container to {} with publisher type {} (see details)",scope, publisher.getClass().getCanonicalName(), e);
|
||||
log.error("cannot add container to {} with publisher type {} (see details)", scope,
|
||||
publisher.getClass().getCanonicalName(), e);
|
||||
|
||||
// since we've failed no published event is fired and profile
|
||||
// will not be stored.
|
||||
// we do it manually to ensure we leave some local trace of the
|
||||
// changed profile.
|
||||
//TODO: CHECK --- store(profile);
|
||||
// TODO: CHECK --- store(profile);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -154,67 +154,66 @@ public class ContainerProfileManager extends ContainerHandler {
|
|||
@Observes(value = removeFromContext)
|
||||
void removeFrom(String scope) {
|
||||
log.info("remove_from_context event arrived in container");
|
||||
for (Publisher publisher: publishers)
|
||||
for (Publisher publisher : publishers)
|
||||
try {
|
||||
log.trace("unpublishing container from context {}", scope);
|
||||
publisher.remove(context,
|
||||
Collections.singleton(scope));
|
||||
publisher.remove(context, Collections.singleton(scope));
|
||||
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
|
||||
log.error("cannot remove container from {} with publisher type {} (see details)",scope, publisher.getClass().getCanonicalName(), e);
|
||||
log.error("cannot remove container from {} with publisher type {} (see details)", scope,
|
||||
publisher.getClass().getCanonicalName(), e);
|
||||
|
||||
// since we've failed no published event is fired and profile
|
||||
// will not be stored.
|
||||
// we do it manually to ensure we leave some local trace of the
|
||||
// changed profile.
|
||||
//TODO: CHECK --- store(profile);
|
||||
// TODO: CHECK --- store(profile);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void schedulePeriodicUpdates() {
|
||||
// register to cancel updates
|
||||
context.events().subscribe(
|
||||
new Object() {
|
||||
// we register it in response to lifecycle events so that we can stop and resume along with application
|
||||
@Observes(value = { activation, part_activation }, kind = resilient)
|
||||
synchronized void restartPeriodicUpdates(ContainerLifecycle lc) {
|
||||
//already running
|
||||
if (periodicUpdates!=null)
|
||||
return;
|
||||
if (lc.state()==active)
|
||||
log.info("scheduling periodic updates of container profile");
|
||||
else
|
||||
log.info("resuming periodic updates of container profile");
|
||||
final Runnable updateTask = new Runnable() {
|
||||
public void run() {
|
||||
context.events().fire(context,changed);
|
||||
}
|
||||
};
|
||||
periodicUpdates = Utils.scheduledServicePool.scheduleAtFixedRate(updateTask, 3, context.configuration()
|
||||
.publicationFrequency(), SECONDS);
|
||||
context.events().subscribe(new Object() {
|
||||
// we register it in response to lifecycle events so that we can stop and resume
|
||||
// along with application
|
||||
@Observes(value = { activation, part_activation }, kind = resilient)
|
||||
synchronized void restartPeriodicUpdates(ContainerLifecycle lc) {
|
||||
// already running
|
||||
if (periodicUpdates != null)
|
||||
return;
|
||||
if (lc.state() == active)
|
||||
log.info("scheduling periodic updates of container profile");
|
||||
else
|
||||
log.info("resuming periodic updates of container profile");
|
||||
final Runnable updateTask = new Runnable() {
|
||||
public void run() {
|
||||
context.events().fire(context, changed);
|
||||
}
|
||||
@Observes(value = { stop, failure, shutdown }, kind = resilient)
|
||||
synchronized void cancelPeriodicUpdates(ContainerLifecycle ignore) {
|
||||
if (periodicUpdates != null){
|
||||
log.trace("stopping periodic updates of container profile");
|
||||
try {
|
||||
periodicUpdates.cancel(true);
|
||||
periodicUpdates=null;
|
||||
}
|
||||
catch(Exception e) {
|
||||
log.warn("could not stop periodic updates of container profile",e);
|
||||
}
|
||||
}
|
||||
};
|
||||
periodicUpdates = Utils.scheduledServicePool.scheduleAtFixedRate(updateTask, 3,
|
||||
context.configuration().publicationFrequency(), SECONDS);
|
||||
}
|
||||
|
||||
@Observes(value = { stop, failure, shutdown }, kind = resilient)
|
||||
synchronized void cancelPeriodicUpdates(ContainerLifecycle ignore) {
|
||||
if (periodicUpdates != null) {
|
||||
log.trace("stopping periodic updates of container profile");
|
||||
try {
|
||||
periodicUpdates.cancel(true);
|
||||
periodicUpdates = null;
|
||||
} catch (Exception e) {
|
||||
log.warn("could not stop periodic updates of container profile", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return profile_management;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.gcube.common.authorization.library.exception.AuthorizationException;
|
||||
import org.gcube.smartgears.Constants;
|
||||
import org.gcube.smartgears.configuration.application.GCubeExclude;
|
||||
import org.gcube.smartgears.configuration.application.GCubeInclude;
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
|
@ -79,7 +80,7 @@ public class RequestManager implements Filter {
|
|||
|
||||
ApplicationPipeline<RequestHandler> pipeline = new ApplicationPipeline<RequestHandler>(filterHandlers);
|
||||
|
||||
log.debug("filtered handler for this call are {}", filterHandlers);
|
||||
log.trace("filtered handler for this call are {}", filterHandlers);
|
||||
|
||||
// create a per-request context with temporary properties
|
||||
ApplicationContext ctx = new DefaultApplicationContext(context);
|
||||
|
@ -124,16 +125,20 @@ public class RequestManager implements Filter {
|
|||
|
||||
String query = request.getQueryString();
|
||||
|
||||
log.debug("servletPath is {} and pathInfo is {}",request.getServletPath(), request.getPathInfo());
|
||||
log.trace("servletPath is {} and pathInfo is {}",request.getServletPath(), request.getPathInfo());
|
||||
|
||||
if ("wsdl".equals(query) || "wsdl=1".equals(query))
|
||||
|
||||
//excludes also mandatory filter for extensions
|
||||
if ("wsdl".equals(query) || "wsdl=1".equals(query) ||
|
||||
request.getServletPath().equals(Constants.root_mapping))
|
||||
return Collections.emptyList();
|
||||
|
||||
|
||||
String path = request.getServletPath()==null?"":request.getServletPath();
|
||||
|
||||
path += request.getPathInfo() ==null?"":request.getPathInfo();
|
||||
|
||||
log.debug("check which handler should be excluded {}", path);
|
||||
log.trace("check which handler should be excluded {}", path);
|
||||
|
||||
if (!context.configuration().excludes().isEmpty()) {
|
||||
log.debug("excludes are not empty");
|
||||
|
@ -148,7 +153,7 @@ public class RequestManager implements Filter {
|
|||
if (exclude.getHandlers().isEmpty()) {
|
||||
List<RequestHandler> unfilterables = handlersToFilter.stream()
|
||||
.filter(RequestHandler::isUnfiltrable).collect(Collectors.toList());
|
||||
log.debug("exclude handler is empty so unfilterable handlers are {}",unfilterables);
|
||||
log.trace("exclude handler is empty so unfilterable handlers are {}",unfilterables);
|
||||
return handlersToFilter.stream()
|
||||
.filter(RequestHandler::isUnfiltrable).collect(Collectors.toList());
|
||||
}
|
||||
|
@ -183,7 +188,7 @@ public class RequestManager implements Filter {
|
|||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
log.debug("returning original handlers");
|
||||
log.trace("returning original handlers");
|
||||
return handlersToFilter;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue