Skip to content

Commit

Permalink
Merge pull request #56 from diging/develop
Browse files Browse the repository at this point in the history
prepare release
  • Loading branch information
jdamerow authored Mar 5, 2018
2 parents d042d1d + 5d8f7d3 commit b5f0ca5
Show file tree
Hide file tree
Showing 14 changed files with 379 additions and 10 deletions.
5 changes: 4 additions & 1 deletion giles-eco/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@

<!-- Solr -->
<giles.freddie.host></giles.freddie.host>


<!-- current requests -->
<current.requests.max.number>20</current.requests.max.number>

<!-- Notification -->
<email.host></email.host>
<email.port>8080</email.port>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ public PasswordEncoder passwordEncoder() {
public SocialUserDetailsService socialUserDetailsService() {
return new SimpleSocialUserDetailsService(userDetailsService());
}

// @Bean(name = "adminDetailsService")
// public UserDetailsService adminDetailsService() {
// return new AdminUserDetailsService();
// }

@Bean
public UserDetailsService userDetailsService() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package edu.asu.diging.gilesecosystem.web.controllers.admin;

import java.util.Collections;
import java.util.List;

import org.bouncycastle.asn1.cms.TimeStampedDataParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import edu.asu.diging.gilesecosystem.web.service.IProcessingRequestService;
import edu.asu.diging.gilesecosystem.web.service.impl.TimestampedRequestData;

@Controller
public class CurrentRequestsController {

@Autowired
private IProcessingRequestService requestService;

@RequestMapping("admin/requests/current")
public String showCurrentRequests() {
return "admin/requests/current";
}

@RequestMapping("admin/requests/current/processed")
public ResponseEntity<List<TimestampedRequestData>> getCurrentProcessedRequests() {
List<TimestampedRequestData> requests = requestService.getCurrentReceivedRequests();
Collections.reverse(requests);
return new ResponseEntity<List<TimestampedRequestData>>(requests, HttpStatus.OK);
}

@RequestMapping("admin/requests/current/sent")
public ResponseEntity<List<TimestampedRequestData>> getCurrentSentRequests() {
List<TimestampedRequestData> requests = requestService.getCurrentSentRequests();
Collections.reverse(requests);
return new ResponseEntity<List<TimestampedRequestData>>(requests, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import edu.asu.diging.gilesecosystem.requests.IRequest;
import edu.asu.diging.gilesecosystem.septemberutil.properties.MessageType;
import edu.asu.diging.gilesecosystem.septemberutil.service.ISystemMessageHandler;
import edu.asu.diging.gilesecosystem.web.service.IProcessingRequestService;
import edu.asu.diging.gilesecosystem.web.service.processing.RequestProcessor;

@PropertySource("classpath:/config.properties")
Expand All @@ -29,6 +30,9 @@ public class KafkaProcessingListener {
@Autowired
private ApplicationContext ctx;

@Autowired
private IProcessingRequestService processingRequestService;

private Map<String, RequestProcessor<? extends IRequest>> requestProcessors;

@Autowired
Expand Down Expand Up @@ -67,6 +71,7 @@ public void receiveMessage(String message, @Header(KafkaHeaders.RECEIVED_TOPIC)
return;
}

processingRequestService.addReceivedRequest(request);
processor.handleRequest(request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package edu.asu.diging.gilesecosystem.web.service;

import java.util.List;

import edu.asu.diging.gilesecosystem.requests.IRequest;
import edu.asu.diging.gilesecosystem.web.service.impl.TimestampedRequestData;

/**
* Service that holds recent processing requests (sent and received).
*
* @author jdamerow
*
*/
public interface IProcessingRequestService {

/**
* Method to append new requests. If there are more than the maximum number of
* current requests in the queue (as specified in the config file), the first one
* is removed from the queue before adding the new one.
*
* This method does not have to be thread-safe as it is ok if there are a few too
* many or too few elements in the queue.
*
* @param request Request to be added to current queue.
*/
void addReceivedRequest(IRequest request);

/**
* Returns recently received requests as a list.
*
* @return List of recently received requests with the oldest request first.
*/
List<TimestampedRequestData> getCurrentReceivedRequests();

/**
* Returns recently sent requests as a list.
*
* @return List of recently sent requests with the oldest request first.
*/
List<TimestampedRequestData> getCurrentSentRequests();

/**
* Method to add a new request to the sent queue. If there are more than the maximum number of
* current requests in the queue (as specified in the config file), the first one
* is removed from the queue before adding the new one.
*
* @param request Sent request to be added to the queue.
*/
void addSentRequest(IRequest request);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package edu.asu.diging.gilesecosystem.web.service.impl;

import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.asu.diging.gilesecosystem.requests.IRequest;
import edu.asu.diging.gilesecosystem.util.properties.IPropertiesManager;
import edu.asu.diging.gilesecosystem.web.service.IProcessingRequestService;
import edu.asu.diging.gilesecosystem.web.service.properties.Properties;

/**
* Not thread-safe implementation of {@link IProcessingRequestService} using a {@link Queue}.
*
* The number of maximum requests in the queue can be defined using the
* property: current_requests_max_number.
*
* @author jdamerow
*
*/
@Service
public class ProcessingRequestService implements IProcessingRequestService {

@Autowired
private IPropertiesManager propertyManager;

private Queue<TimestampedRequestData> currentReceivedRequests;

private Queue<TimestampedRequestData> currentSentRequests;

@PostConstruct
public void init() {
currentReceivedRequests = new ConcurrentLinkedQueue<>();
currentSentRequests = new ConcurrentLinkedQueue<>();
}

/* (non-Javadoc)
* @see edu.asu.diging.gilesecosystem.web.service.impl.IProcessingRequestService#addReceivedRequest(edu.asu.diging.gilesecosystem.requests.IRequest)
*/
@Override
public void addReceivedRequest(IRequest request) {
if (currentReceivedRequests.size() > new Integer(propertyManager.getProperty(Properties.CURRENT_REQUESTS_MAX))) {
currentReceivedRequests.poll();
}
currentReceivedRequests.add(new TimestampedRequestData(request, ZonedDateTime.now()));
}

/* (non-Javadoc)
* @see edu.asu.diging.gilesecosystem.web.service.impl.IProcessingRequestService#getCurrentReceivedRequests()
*/
@Override
public List<TimestampedRequestData> getCurrentReceivedRequests() {
return new ArrayList<>(currentReceivedRequests);
}

@Override
public void addSentRequest(IRequest request) {
if (currentSentRequests.size() > new Integer(propertyManager.getProperty(Properties.CURRENT_REQUESTS_MAX))) {
currentSentRequests.poll();
}
currentSentRequests.add(new TimestampedRequestData(request, ZonedDateTime.now()));
}

@Override
public List<TimestampedRequestData> getCurrentSentRequests() {
return new ArrayList<>(currentSentRequests);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package edu.asu.diging.gilesecosystem.web.service.impl;

import java.time.ZonedDateTime;

import edu.asu.diging.gilesecosystem.requests.IRequest;

public class TimestampedRequestData {
public IRequest request;
public ZonedDateTime time;

public TimestampedRequestData(IRequest request, ZonedDateTime time) {
this.request = request;
this.time = time;
}

public IRequest getRequest() {
return request;
}
public void setRequest(IRequest request) {
this.request = request;
}
public ZonedDateTime getTime() {
return time;
}
public void setTime(ZonedDateTime time) {
this.time = time;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import edu.asu.diging.gilesecosystem.web.domain.impl.File;
import edu.asu.diging.gilesecosystem.web.domain.impl.ProcessingRequest;
import edu.asu.diging.gilesecosystem.web.exceptions.GilesProcessingException;
import edu.asu.diging.gilesecosystem.web.service.IProcessingRequestService;
import edu.asu.diging.gilesecosystem.web.service.core.ITransactionalFileService;
import edu.asu.diging.gilesecosystem.web.service.core.ITransactionalProcessingRequestService;
import edu.asu.diging.gilesecosystem.web.service.processing.helpers.RequestHelper;
Expand Down Expand Up @@ -49,6 +50,9 @@ public abstract class ACompletedExtractionProcessor extends ACompletedRequestPro

@Autowired
private ISystemMessageHandler messageHandler;

@Autowired
private IProcessingRequestService requestService;

protected void sendStorageRequest(IFile file, String downloadPath, String downloadUrl, FileType type) {
IStorageRequest storageRequest;
Expand All @@ -68,6 +72,7 @@ protected void sendStorageRequest(IFile file, String downloadPath, String downlo
procReq.setRequestId(storageRequest.getRequestId());
processingRequestService.saveNewProcessingRequest(procReq);

requestService.addSentRequest(storageRequest);
try {
requestProducer.sendRequest(storageRequest, propertyManager.getProperty(Properties.KAFKA_TOPIC_STORAGE_REQUEST));
} catch (MessageCreationException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import edu.asu.diging.gilesecosystem.web.domain.ProcessingStatus;
import edu.asu.diging.gilesecosystem.web.domain.impl.ProcessingRequest;
import edu.asu.diging.gilesecosystem.web.exceptions.GilesProcessingException;
import edu.asu.diging.gilesecosystem.web.service.IProcessingRequestService;
import edu.asu.diging.gilesecosystem.web.service.core.ITransactionalDocumentService;
import edu.asu.diging.gilesecosystem.web.service.core.ITransactionalFileService;
import edu.asu.diging.gilesecosystem.web.service.core.ITransactionalProcessingRequestService;
Expand Down Expand Up @@ -42,6 +43,9 @@ public abstract class ProcessingPhase<T extends IProcessingInfo> implements IPro
@Autowired
private ISystemMessageHandler messageHandler;

@Autowired
private IProcessingRequestService requestService;

public RequestStatus process(IFile file, IProcessingInfo info)
throws GilesProcessingException {

Expand Down Expand Up @@ -100,6 +104,7 @@ public RequestStatus process(IFile file, IProcessingInfo info)

public void sendRequest(IRequest request, IDocument document)
throws GilesProcessingException {
requestService.addSentRequest(request);
try {
requestProducer.sendRequest(request, getTopic());
} catch (MessageCreationException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ public interface Properties {

public final static String NEPOMUK_PING_ENDPOINT = "nepomuk_ping_endpoint";
public final static String NEPOMUK_FILES_ENDPOINT = "nepomuk_files_endpoint";

public final static String CURRENT_REQUESTS_MAX = "current_requests_max_number";
}
5 changes: 4 additions & 1 deletion giles-eco/src/main/resources/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ processor_color_freddie=yellowgreen

# Email notification
email_enabled=${email.enabled}
email_from=${email.from}
email_from=${email.from}

# Current requests
current_requests_max_number=${current.requests.max.number}
5 changes: 5 additions & 0 deletions giles-eco/src/main/webapp/WEB-INF/tiles-defs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
<put-attribute name="content" value="/WEB-INF/views/admin/deleteApp.jsp" />
</definition>

<!-- Requests -->
<definition name="admin/requests/current" extends="base.definition">
<put-attribute name="content" value="/WEB-INF/views/admin/currentRequests.jsp" />
</definition>

<!-- Migration -->
<definition name="admin/migrate" extends="base.definition">
<put-attribute name="content" value="/WEB-INF/views/admin/migrate/migrate.jsp" />
Expand Down
10 changes: 7 additions & 3 deletions giles-eco/src/main/webapp/WEB-INF/tiles/skeleton.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@
<li role="presentation">
<a href="<c:url value="/admin/apps" />" >Apps</a>
</li>
<li role="presentation">
<a href="<c:url value="/admin/requests" />">Requests</a>
</li>
<li role="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Requests<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="<c:url value="/admin/requests" />">Resend Requests</a></li>
<li><a href="<c:url value="/admin/requests/current" />">Monitor Requests</a></li>
</ul>
</li>
</sec:authorize>
<sec:authorize access="isAuthenticated()">
<li role="presentation">
Expand Down
Loading

0 comments on commit b5f0ca5

Please sign in to comment.