/** * Takes the input reader of the XML file and instantiates an instance of the ChecksumList class * * <p> * * @param r The input reader of the version XML file * @throw ClassCastException If the input file does not map to ChecksumList * @throw JAXBException Upon error reading the XML file */ public static RunnerChecksums decode(Reader r) throws JAXBException { Unmarshaller unmarshaller = context.createUnmarshaller(); RunnerChecksums rc = (RunnerChecksums) unmarshaller.unmarshal(r); /* Convert metadata to internal representation */ if (rc.checksums != null) { rc.internalChecksums = new LinkedHashMap<String, RunnerChecksum>(); for (RunnerChecksum c : rc.checksums) { rc.internalChecksums.put(c.getPathName(), c); } } else { rc.internalChecksums = null; } return rc; }
/** * Creates an returns a new instance of the RunnerCheckums object given a set of asset types to * accept. This will search all deployed modules for assets of that type * * @param types the set of acceptable type of asset * @param builder the UriBuilder for generating URLs */ public static RunnerChecksums generate(List<String> types, UriBuilder builder) { Map<String, RunnerChecksum> out = new LinkedHashMap<String, RunnerChecksum>(); /* * Get a map of all of the Checksum objects for each art asset. We see * if the module name matches each entry and collect its checksum * entries into a single map. */ Map<DeployedAsset, File> partMap = AssetDeployer.getFileMap(); for (DeployedAsset asset : partMap.keySet()) { if (types.contains(asset.assetType)) { String moduleName = asset.moduleName; // go through each checksum, and create a checksum // to add to the output. If there is no factory to load the // checksum for the asset, the go onto the next deployed asset // part ModuleAssetDescriptor mad = new ModuleAssetDescriptor(moduleName, asset.assetType, null); ChecksumManager checksumManager = ChecksumManager.getChecksumManager(); ChecksumFactory factory = checksumManager.getChecksumFactory(mad); ChecksumList checksumList = factory.getChecksumList(mad, ChecksumAction.DO_NOT_GENERATE); if (checksumList == null) { continue; } for (Map.Entry<String, Checksum> e : checksumList.getChecksumMap().entrySet()) { String assetName = e.getKey(); Checksum assetChecksum = e.getValue(); try { URL assetURL = getAssetURL(builder, moduleName, assetName); out.put(assetName, new RunnerChecksum(assetChecksum, moduleName, assetURL)); } catch (IOException ioe) { logger.log(Level.WARNING, "Error getting url for " + assetName, ioe); } } } } // create the checksums object to write RunnerChecksums ret = new RunnerChecksums(); ret.putChecksums(out); return ret; }
/** * Returns the checksums information about the deployed runners * * @return An XML encoding of the module's basic information */ @GET @Produces("text/plain") public Response getModuleChecksums() { List<String> types = new ArrayList<String>(); types.add("timelineprovider"); RunnerChecksums checksums = RunnerChecksums.generate(types, uriInfo.getBaseUriBuilder()); /* Write the XML encoding to a writer and return it */ StringWriter sw = new StringWriter(); try { checksums.encode(sw); ResponseBuilder rb = Response.ok(sw.toString()); return rb.build(); } catch (javax.xml.bind.JAXBException excp) { /* Log an error and return an error response */ logger.log(Level.WARNING, "[ASSET] Unable to encode checksums", excp); ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST); return rb.build(); } }