Skip to content

Commit

Permalink
https://github.com/metadatacenter/cedar-project/issues/1198
Browse files Browse the repository at this point in the history
  • Loading branch information
Attila L. Egyedi committed Nov 8, 2023
1 parent 2cde375 commit c44b66e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cedar-worker-server-application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
<artifactId>cedar-valuerecommender-operations-library</artifactId>
</dependency>

<dependency>
<groupId>org.metadatacenter</groupId>
<artifactId>cedar-inclusion-subgraph-library</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.knowm.dropwizard.sundial.SundialConfiguration;
import org.metadatacenter.cedar.util.dw.CedarMicroserviceApplication;
import org.metadatacenter.cedar.worker.health.WorkerServerHealthCheck;
import org.metadatacenter.cedar.worker.resources.CommandInclusionSubgraphResource;
import org.metadatacenter.cedar.worker.resources.IndexResource;
import org.metadatacenter.config.CedarConfig;
import org.metadatacenter.model.ServerName;
Expand Down Expand Up @@ -89,6 +90,8 @@ public void initializeApp() {
valuerecommenderQueueService = new ValuerecommenderReindexQueueService(cedarConfig.getCacheConfig().getPersistent());
valuerecommenderExecutorService = new ValuerecommenderReindexExecutorService(cedarConfig, valuerecommenderQueueService);
valuerecommenderExecutorService.init(userService);

CommandInclusionSubgraphResource.injectUserService(userService);
}

@Override
Expand All @@ -100,6 +103,9 @@ public void runApp(WorkerServerConfiguration configuration, Environment environm
final WorkerServerHealthCheck healthCheck = new WorkerServerHealthCheck();
environment.healthChecks().register("message", healthCheck);

final CommandInclusionSubgraphResource commandInclusionsubgraph = new CommandInclusionSubgraphResource(cedarConfig);
environment.jersey().register(commandInclusionsubgraph);

PermissionQueueProcessor searchPermissionProcessor = new PermissionQueueProcessor(permissionQueueService, searchPermissionExecutorService);
environment.lifecycle().manage(searchPermissionProcessor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public WorkerServerHealthCheck() {
}

@Override
protected Result check() throws Exception {
protected Result check() {
if (2 * 2 == 5) {
return Result.unhealthy("Unhealthy, because 2 * 2 == 5");
}
return Result.healthy();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.metadatacenter.cedar.worker.resources;

import com.codahale.metrics.annotation.Timed;
import org.metadatacenter.config.CedarConfig;
import org.metadatacenter.exception.CedarException;
import org.metadatacenter.exception.CedarProcessingException;
import org.metadatacenter.rest.context.CedarRequestContext;
import org.metadatacenter.rest.context.CedarRequestContextFactory;
import org.metadatacenter.server.search.util.RegenerateInclusionSubgraphTask;
import org.metadatacenter.server.security.model.auth.CedarPermission;
import org.metadatacenter.server.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static org.metadatacenter.rest.assertion.GenericAssertions.LoggedIn;

@Path("/command")
@Produces(MediaType.APPLICATION_JSON)
public class CommandInclusionSubgraphResource extends AbstractWorkerResource {

private static final Logger log = LoggerFactory.getLogger(CommandInclusionSubgraphResource.class);
private static UserService userService;

public CommandInclusionSubgraphResource(CedarConfig cedarConfig) {
super(cedarConfig);
}

public static void injectUserService(UserService us) {
userService = us;
}

@POST
@Timed
@Path("/regenerate-inclusion-subgraph")
public Response regenerateRulesIndex() throws CedarException {
CedarRequestContext c = buildRequestContext();
c.must(c.user()).be(LoggedIn);
c.must(c.user()).have(CedarPermission.INCLUSION_SUBGRAPH_RECREATE);

ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> {
RegenerateInclusionSubgraphTask task = new RegenerateInclusionSubgraphTask(cedarConfig);
try {
CedarRequestContext cedarAdminRequestContext = CedarRequestContextFactory.fromAdminUser(cedarConfig, userService);
task.regenerateInclusionSubgraph(cedarAdminRequestContext);
} catch (CedarProcessingException e) {
//TODO: handle this, log it separately
log.error("Error in inclusion subgraph regeneration executor", e);
}
});

return Response.ok().build();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ logger.hibernate.level = warn

logger.netty.name = io.netty.util.internal
logger.netty.level = warn

logger.elasticsearch.name = org.elasticsearch.transport
logger.elasticsearch.level = warn

0 comments on commit c44b66e

Please sign in to comment.