Search in sources :

Example 1 with BundleResponse

use of org.onebusaway.admin.model.BundleResponse in project onebusaway-application-modules by camsys.

the class BundleRequestServiceImpl method validate.

@Override
public /**
 * Make an asynchronous request to validate bundle(s).  The BundleResponse object is
 * updated upon completion (successful or otherwise) of the validation process.
 */
BundleResponse validate(BundleRequest bundleRequest) {
    String id = getNextId();
    bundleRequest.setId(id);
    BundleResponse bundleResponse = new BundleResponse(id);
    bundleResponse.addStatusMessage("queueing...");
    _log.debug("validate id=" + bundleResponse.getId());
    _validationMap.put(bundleResponse.getId(), bundleResponse);
    _executorService.execute(new ValidateThread(bundleRequest, bundleResponse));
    return bundleResponse;
}
Also used : BundleResponse(org.onebusaway.admin.model.BundleResponse)

Example 2 with BundleResponse

use of org.onebusaway.admin.model.BundleResponse in project onebusaway-application-modules by camsys.

the class BundleRequestServiceImplTest method setup.

@Before
public void setup() {
    BundleValidationServiceImpl validationService = new BundleValidationServiceImpl();
    service = new BundleRequestServiceImpl();
    service.setInstanceId("localhost");
    service.setup();
    FileService fileService = new S3FileServiceImpl() {

        @Override
        public void setup() {
        }

        @Override
        public boolean bundleDirectoryExists(String filename) {
            return !"noSuchDirectory".equals(filename);
        }

        @Override
        public boolean createBundleDirectory(String filename) {
            return true;
        }

        @Override
        public List<String[]> listBundleDirectories(int maxResults) {
            ArrayList<String[]> list = new ArrayList<String[]>();
            String[] columns = { "2012April/", "", "" + System.currentTimeMillis() };
            list.add(columns);
            return list;
        }

        @Override
        public List<String> list(String directory, int maxResults) {
            ArrayList<String> list = new ArrayList<String>();
            list.add("google_transit_brooklyn.zip");
            list.add("google_transit_staten_island.zip");
            return list;
        }

        @Override
        public String get(String key, String tmpDir) {
            InputStream input = this.getClass().getResourceAsStream("empty_feed.zip");
            String destination = "/tmp/empty_feed.zip.html";
            new NYCFileUtils().copy(input, destination);
            return destination;
        }

        @Override
        public String put(String key, String tmpDir) {
            // no op
            return null;
        }
    };
    fileService.setup();
    fileService.setBucketName("obanyc-bundle-data-test");
    BundleServerServiceImpl bundleServer = new BundleServerServiceImpl() {

        @Override
        public void setup() {
        // no op
        }

        @Override
        public String start(String instanceId) {
            return instanceId;
        }

        @Override
        public String pollPublicDns(String instanceId, int maxWaitSeconds) {
            return "localhost";
        }

        @Override
        public String findPublicDns(String instanceId) {
            return "localhost";
        }

        @Override
        public String findPublicIp(String instanceId) {
            return "127.0.0.1";
        }

        @Override
        public String stop(String instanceId) {
            return instanceId;
        }

        @Override
        public boolean ping(String instanceId) {
            return true;
        }

        @SuppressWarnings("unchecked")
        @Override
        public <T> T makeRequest(String instanceId, String apiCall, Object payload, Class<T> returnType, int waitTimeInSeconds, Map params, String sessionId) {
            _log.debug("makeRequest called with apiCall=" + apiCall + " and payload=" + payload);
            if (apiCall.equals("/validate/remote/2012Jan/test_0/1/create")) {
                BundleResponse br = new BundleResponse("1");
                return (T) br;
            } else if (apiCall.equals("/build/remote/2012Jan/test_0/null/1/2012-04-08/2012-07-07/create") || apiCall.equals("/build/remote/create")) {
                BundleBuildResponse br = new BundleBuildResponse("1");
                return (T) br;
            } else if (apiCall.equals("/ping/remote")) {
                return (T) "{1}";
            } else if (apiCall.equals("/validate/remote/1/list")) {
                BundleResponse br = new BundleResponse("1");
                br.addValidationFile("file1");
                br.addValidationFile("file2");
                br.setComplete(true);
                return (T) br;
            } else if (apiCall.equals("/build/remote/1/list")) {
                BundleBuildResponse br = new BundleBuildResponse("1");
                br.addGtfsFile("file1");
                br.addGtfsFile("file2");
                br.setComplete(true);
                return (T) br;
            } else {
                _log.error("unmatched apiCall=|" + apiCall + "|");
            }
            return null;
        }
    };
    bundleServer.setEc2User("user");
    bundleServer.setEc2Password("password");
    bundleServer.setup();
    service.setBundleServerService(bundleServer);
    validationService.setFileService(fileService);
}
Also used : FileService(org.onebusaway.admin.service.FileService) BundleResponse(org.onebusaway.admin.model.BundleResponse) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BundleServerServiceImpl(org.onebusaway.admin.service.server.impl.BundleServerServiceImpl) S3FileServiceImpl(org.onebusaway.admin.service.impl.S3FileServiceImpl) NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) BundleValidationServiceImpl(org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl) BundleRequestServiceImpl(org.onebusaway.admin.service.impl.BundleRequestServiceImpl) BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) Map(java.util.Map) Before(org.junit.Before)

Example 3 with BundleResponse

use of org.onebusaway.admin.model.BundleResponse in project onebusaway-application-modules by camsys.

the class ValidateRemoteResource method list.

@Path("/{id}/list")
@GET
@Produces("application/json")
public Response list(@PathParam("id") String id) {
    Response response = null;
    if (!isAuthorized()) {
        return Response.noContent().build();
    }
    try {
        final StringWriter sw = new StringWriter();
        final MappingJsonFactory jsonFactory = new MappingJsonFactory();
        final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
        BundleResponse bundleResponse = _validationMap.get(id);
        _log.debug("found bundleResponse=" + bundleResponse + " for id=" + id);
        _mapper.writeValue(jsonGenerator, bundleResponse);
        response = Response.ok(sw.toString()).build();
    } catch (Exception any) {
        response = Response.serverError().build();
    }
    return response;
}
Also used : BundleResponse(org.onebusaway.admin.model.BundleResponse) Response(javax.ws.rs.core.Response) MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) StringWriter(java.io.StringWriter) BundleResponse(org.onebusaway.admin.model.BundleResponse) JsonGenerator(org.codehaus.jackson.JsonGenerator) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with BundleResponse

use of org.onebusaway.admin.model.BundleResponse in project onebusaway-application-modules by camsys.

the class ValidateResource method validate.

@Path("/{bundleDirectory}/{bundleName}/create")
@GET
@Produces("application/json")
public Response validate(@PathParam("bundleDirectory") String bundleDirectory, @PathParam("bundleName") String bundleName) {
    Response response = null;
    if (!isAuthorized()) {
        return Response.noContent().build();
    }
    BundleRequest bundleRequest = new BundleRequest();
    directoryName = bundleDirectory;
    this.bundleName = bundleName;
    bundleRequest.setBundleBuildName(bundleName);
    bundleRequest.setBundleDirectory(bundleDirectory);
    String session = RequestContextHolder.currentRequestAttributes().getSessionId();
    bundleRequest.setSessionId(session);
    BundleResponse bundleResponse = null;
    try {
        bundleResponse = _bundleService.validate(bundleRequest);
        final StringWriter sw = new StringWriter();
        final MappingJsonFactory jsonFactory = new MappingJsonFactory();
        final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
        _mapper.writeValue(jsonGenerator, bundleResponse);
        response = Response.ok(sw.toString()).build();
    } catch (Exception any) {
        _log.error("validate resource caught exception:" + any);
        response = Response.serverError().build();
    }
    return response;
}
Also used : BundleResponse(org.onebusaway.admin.model.BundleResponse) Response(javax.ws.rs.core.Response) MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) BundleResponse(org.onebusaway.admin.model.BundleResponse) StringWriter(java.io.StringWriter) BundleRequest(org.onebusaway.admin.model.BundleRequest) JsonGenerator(org.codehaus.jackson.JsonGenerator) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with BundleResponse

use of org.onebusaway.admin.model.BundleResponse in project onebusaway-application-modules by camsys.

the class BundleRequestServiceImplTest method testValidate.

@Test
public void testValidate() throws Exception {
    BundleRequest req = new BundleRequest();
    String key = "2012Jan";
    // String key = "m34"; // use for faster testing
    req.setBundleDirectory(key);
    req.setBundleBuildName("test_0");
    _log.debug("calling validate for dir=" + req.getBundleDirectory() + " name=" + req.getBundleBuildName());
    BundleResponse res = service.validate(req);
    assertFalse(res.isComplete());
    int count = 0;
    while (count < 300 && !res.isComplete() && res.getException() == null) {
        // _log.info("sleeping[" + count + "]...");
        Thread.sleep(10 * 1000);
        count++;
        // NOTE: this is optional to demonstrate retrieval service
        _log.debug("calling lookup(local) for id=" + res.getId());
        res = service.lookupValidationRequest(res.getId());
        assertNotNull(res);
    }
    if (res.getException() != null) {
        _log.error("Failed with exception=" + res.getException());
    }
    assertNull(res.getException());
    assertTrue(res.isComplete());
    assertNotNull(res.getValidationFiles());
    assertEquals(2, res.getValidationFiles().size());
}
Also used : BundleResponse(org.onebusaway.admin.model.BundleResponse) BundleRequest(org.onebusaway.admin.model.BundleRequest) Test(org.junit.Test)

Aggregations

BundleResponse (org.onebusaway.admin.model.BundleResponse)7 StringWriter (java.io.StringWriter)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Response (javax.ws.rs.core.Response)4 JsonGenerator (org.codehaus.jackson.JsonGenerator)4 MappingJsonFactory (org.codehaus.jackson.map.MappingJsonFactory)4 BundleRequest (org.onebusaway.admin.model.BundleRequest)3 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Before (org.junit.Before)1 Test (org.junit.Test)1 BundleBuildResponse (org.onebusaway.admin.model.BundleBuildResponse)1 FileService (org.onebusaway.admin.service.FileService)1 BundleValidationServiceImpl (org.onebusaway.admin.service.bundle.impl.BundleValidationServiceImpl)1 BundleRequestServiceImpl (org.onebusaway.admin.service.impl.BundleRequestServiceImpl)1 S3FileServiceImpl (org.onebusaway.admin.service.impl.S3FileServiceImpl)1 BundleServerServiceImpl (org.onebusaway.admin.service.server.impl.BundleServerServiceImpl)1