Search in sources :

Example 1 with BundleBuildResponse

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

the class BundleRequestServiceImpl method build.

@Override
public BundleBuildResponse build(BundleBuildRequest bundleRequest) {
    String id = getNextId();
    bundleRequest.setId(id);
    BundleBuildResponse bundleResponse = new BundleBuildResponse(id);
    bundleResponse.setBundleBuildName(bundleRequest.getBundleName());
    bundleResponse.setBundleStartDate(bundleRequest.getBundleStartDateString());
    bundleResponse.setBundleEndDate(bundleRequest.getBundleEndDateString());
    bundleResponse.setBundleComment(bundleRequest.getBundleComment());
    _buildMap.put(bundleResponse.getId(), bundleResponse);
    bundleResponse.addStatusMessage("queueing...");
    if (_bundleService != null) {
        _bundleService.createBundleBuildResponse(bundleResponse);
    }
    _executorService.execute(new BuildThread(bundleRequest, bundleResponse));
    return bundleResponse;
}
Also used : BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse)

Example 2 with BundleBuildResponse

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

the class BundleBuildingServiceImplTest method testBuildHastus.

private void testBuildHastus() {
    _service.setAuxConfig("true");
    String bundleDir = "test";
    String tmpDir = new NYCFileUtils().createTmpDirectory();
    BundleBuildRequest request = new BundleBuildRequest();
    request.setBundleDirectory(bundleDir);
    request.setBundleName("testnameHastus");
    request.setTmpDirectory(tmpDir);
    request.setBundleStartDate("2012-04-08");
    request.setBundleEndDate("2012-07-07");
    assertNotNull(request.getTmpDirectory());
    assertNotNull(request.getBundleDirectory());
    BundleBuildResponse response = new BundleBuildResponse("" + System.currentTimeMillis());
    assertEquals(0, response.getStatusList().size());
    // step 1
    _service.download(request, response);
    assertNotNull(response.getGtfsList());
    assertEquals(1, response.getGtfsList().size());
    assertNotNull(response.getAuxZipList());
    assertEquals(2, response.getAuxZipList().size());
    assertNotNull(response.getStatusList());
    assertTrue(response.getStatusList().size() > 0);
    assertNotNull(response.getConfigList());
    assertEquals(0, response.getConfigList().size());
    // step 2
    _service.prepare(request, response);
    assertFalse(response.isComplete());
    // step 3
    int rc = _service.build(request, response);
    if (response.getException() != null) {
        _log.error("Failed with exception=" + response.getException(), response.getException());
    }
    assertNull(response.getException());
    assertFalse(response.isComplete());
    assertEquals(0, rc);
    // step 4
    // OBANYC-1451 -- fails on OSX TODO
    // _service.assemble(request, response);
    // step 5
    _service.upload(request, response);
    // set by BundleRequestService
    assertFalse(response.isComplete());
}
Also used : BundleBuildRequest(org.onebusaway.admin.model.BundleBuildRequest) NYCFileUtils(org.onebusaway.admin.util.NYCFileUtils) BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse)

Example 3 with BundleBuildResponse

use of org.onebusaway.admin.model.BundleBuildResponse 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 4 with BundleBuildResponse

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

the class BuildResource 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();
    }
    BundleBuildResponse buildResponse = _bundleService.lookupBuildRequest(id);
    String dirName = buildResponse.getBundleDirectoryName();
    if (dirName == null || dirName.isEmpty()) {
        buildResponse.setBundleBuildName(bundleName);
        buildResponse.setBundleDirectoryName(directoryName);
        buildResponse.setBundleEmailTo(emailTo);
        buildResponse.setBundleStartDate(startDate);
        buildResponse.setBundleEndDate(endDate);
        buildResponse.setBundleComment(comment);
    }
    try {
        final StringWriter sw = new StringWriter();
        final MappingJsonFactory jsonFactory = new MappingJsonFactory();
        final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
        _mapper.writeValue(jsonGenerator, buildResponse);
        response = Response.ok(sw.toString()).build();
    } catch (Exception any) {
        _log.error("exception looking up build:", any);
        response = Response.serverError().build();
    }
    return response;
}
Also used : BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) Response(javax.ws.rs.core.Response) MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) StringWriter(java.io.StringWriter) JsonGenerator(org.codehaus.jackson.JsonGenerator) BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) DateValidationException(org.onebusaway.admin.service.exceptions.DateValidationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with BundleBuildResponse

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

the class BuildRemoteResource method build.

@Path("/create")
@POST
@Produces("application/json")
public Response build(@FormParam("bundleDirectory") String bundleDirectory, @FormParam("bundleBuildName") String bundleName, @FormParam("email") String email, @FormParam("id") String id, @FormParam("bundleStartDate") String bundleStartDate, @FormParam("bundleEndDate") String bundleEndDate, @FormParam("bundleComment") String bundleComment, @FormParam("archive") boolean archive, @FormParam("consolidate") boolean consolidate, @FormParam("predate") boolean predate) {
    Response response = null;
    if (!isAuthorized()) {
        return Response.noContent().build();
    }
    _log.info("in build(local) with archive=" + archive + ", and consolidate=" + consolidate);
    BundleBuildRequest bundleRequest = new BundleBuildRequest();
    bundleRequest.setBundleDirectory(bundleDirectory);
    bundleRequest.setBundleName(bundleName);
    bundleRequest.setEmailAddress(email);
    bundleRequest.setId(id);
    bundleRequest.setBundleStartDate(bundleStartDate);
    bundleRequest.setBundleEndDate(bundleEndDate);
    bundleRequest.setBundleComment(bundleComment);
    bundleRequest.setArchiveFlag(archive);
    bundleRequest.setConsolidateFlag(consolidate);
    bundleRequest.setPredate(predate);
    BundleBuildResponse bundleResponse = new BundleBuildResponse(id);
    try {
        bundleResponse.addStatusMessage("server started");
        bundleResponse.addStatusMessage("queueing");
        // place execution in its own thread
        _executorService.execute(new BuildThread(bundleRequest, bundleResponse));
        // place handle to response in map
        _buildMap.put(id, bundleResponse);
        final StringWriter sw = new StringWriter();
        final MappingJsonFactory jsonFactory = new MappingJsonFactory();
        final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
        // write back response
        _mapper.writeValue(jsonGenerator, bundleResponse);
        response = Response.ok(sw.toString()).build();
    } catch (Exception any) {
        _log.error("execption in build:", any);
        response = Response.serverError().build();
    }
    return response;
}
Also used : BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) Response(javax.ws.rs.core.Response) BundleBuildRequest(org.onebusaway.admin.model.BundleBuildRequest) MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) StringWriter(java.io.StringWriter) JsonGenerator(org.codehaus.jackson.JsonGenerator) BundleBuildResponse(org.onebusaway.admin.model.BundleBuildResponse) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

BundleBuildResponse (org.onebusaway.admin.model.BundleBuildResponse)13 BundleBuildRequest (org.onebusaway.admin.model.BundleBuildRequest)6 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 Response (javax.ws.rs.core.Response)5 NYCFileUtils (org.onebusaway.admin.util.NYCFileUtils)4 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 GET (javax.ws.rs.GET)3 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)3 JsonGenerator (org.codehaus.jackson.JsonGenerator)3 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)3 MappingJsonFactory (org.codehaus.jackson.map.MappingJsonFactory)3 DateValidationException (org.onebusaway.admin.service.exceptions.DateValidationException)3 POST (javax.ws.rs.POST)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Map (java.util.Map)1 Session (org.hibernate.Session)1