Package org.jdesktop.wonderland.modules.service

Examples of org.jdesktop.wonderland.modules.service.ModuleManager


    public Response getModuleRepository(@PathParam("modulename") String moduleName) {
        /* Fetch thhe error logger for use in this method */
        Logger logger = ModuleManager.getLogger();
       
        /* Fetch the module from the module manager */
        ModuleManager manager = ModuleManager.getModuleManager();
        Module module = manager.getInstalledModules().get(moduleName);
        if (module == null) {
            /* Log an error and return an error response */
            logger.warning("ModuleManager: unable to locate module " + moduleName);
            ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
            return rb.build();
View Full Code Here


        /*
         * Create a factory for disk-base file items to handle the request. Also
         * place the file in add/.
         */
        String redirect = "/installFailed.jsp";
        ModuleManager manager = ModuleManager.getModuleManager();
       
        /* Check that we have a file upload request */
        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        if (isMultipart == false) {
            LOGGER.warning("Failed to upload module, isMultipart=false");
            String msg = "Unable to recognize upload request. Please try again.";
            request.setAttribute("errorMessage", msg);
            RequestDispatcher rd = request.getRequestDispatcher(redirect);
            rd.forward(request, response);
            return;
        }
        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload();

        // Parse the request
        try {
            FileItemIterator iter = upload.getItemIterator(request);
            while (iter.hasNext() == true) {
                FileItemStream item = iter.next();
                InputStream stream = item.openStream();
                if (item.isFormField() == false) {
                    /*
                     * The name given should have a .jar extension. Check this here. If
                     * not, return an error. If so, parse out just the module name.
                     */
                    String moduleJar = item.getName();
                    if (moduleJar.endsWith(".jar") == false) {
                        /* Log an error to the log and write an error message back */
                        LOGGER.warning("Upload is not a jar file " + moduleJar);
                        String msg = "The file " + moduleJar + " needs to be" +
                                " a jar file. Please try again.";
                        request.setAttribute("errorMessage", msg);
                        RequestDispatcher rd = request.getRequestDispatcher(redirect);
                        rd.forward(request, response);
                        return;
                    }
                    String moduleName = moduleJar.substring(0, moduleJar.length() - 4);

                    LOGGER.info("Upload Install module " + moduleName +
                            " with file name " + moduleJar);
                   
                    /*
                     * Write the file a temporary file
                     */
                    File tmpFile = null;
                    try {
                        tmpFile = File.createTempFile(moduleName+"_tmp", ".jar");
                        tmpFile.deleteOnExit();
                        RunUtil.writeToFile(stream, tmpFile);
                    } catch (java.lang.Exception excp) {
                        /* Log an error to the log and write an error message back */
                        LOGGER.log(Level.WARNING, "Failed to save file", excp);
                        String msg = "Internal error installing the module.";
                        request.setAttribute("errorMessage", msg);
                        RequestDispatcher rd = request.getRequestDispatcher(redirect);
                        rd.forward(request, response);
                        return;
                    }

                    /* Add the new module */
                    Collection<File> moduleFiles = new LinkedList<File>();
                    moduleFiles.add(tmpFile);
                    Collection<Module> result = manager.addToInstall(moduleFiles);
                    if (result.isEmpty() == true) {
                        /* Log an error to the log and write an error message back */
                        LOGGER.warning("Failed to install module " + moduleName);
                        String msg = "Internal error installing the module.";
                        request.setAttribute("errorMessage", msg);
                        RequestDispatcher rd = request.getRequestDispatcher(redirect);
                        rd.forward(request, response);
                        return;
                    }
                }
            }
        } catch (FileUploadException excp) {
            /* Log an error to the log and write an error message back */
            LOGGER.log(Level.WARNING, "File upload failed", excp);
            String msg = "Failed to upload the file. Please try again.";
            request.setAttribute("errorMessage", msg);
            RequestDispatcher rd = request.getRequestDispatcher(redirect);
            rd.forward(request, response);
            return;
        }
        /* Install all of the modules that are possible */
        manager.installAll();
       
        /* If we have reached here, then post a simple message */
        LOGGER.info("Added module successfully");
        RequestDispatcher rd = request.getRequestDispatcher("/installSuccess.jsp");
        rd.forward(request, response);
View Full Code Here

        String redirect = (confirm == true) ? "/confirmRemove.jsp" : "/index.jsp";
       
        // Go ahead and remove the modules and then redirect to the index.jsp
        // page.
        if (confirm == false) {
            ModuleManager manager = ModuleManager.getModuleManager();
            List<String> moduleNames = Arrays.asList(removeModuleNames);
            manager.addToUninstall(moduleNames);
            manager.uninstallAll();
        }
       
        RequestDispatcher rd = request.getRequestDispatcher(redirect);
        rd.forward(request, response);
    }
View Full Code Here

     * @param props the properties to run with
     * @throws IOException if there is an error deploying files
     */
    @Override
    protected void deployFiles(Properties props) throws IOException {
        ModuleManager mm = ModuleManager.getModuleManager();
       
        // first tell the module manager to remove any modules scheduled for
        // removal
        mm.uninstallAll();

        // next tell the module manager to install any pending modules
        mm.installAll();

        // then call the super class's deployFiles() method, which will
        // call the other methods in this class
        super.deployFiles(props);

View Full Code Here

     * Update any system-installed module to be the latest version from
     * the Wonderland.jar file.
     * @throws IOException if there is an error reading or writing modules
     */
    protected void updateModules() throws IOException {
        ModuleManager mm = ModuleManager.getModuleManager();

        // create the directory to extract modules to, if it doesn't already
        // exist
        File moduleDir = RunUtil.createTempDir("module", ".jar");

        // read the list of modules and their checksums from the jar file
        Map<String, String> checksums =
                FileListUtil.readChecksums("META-INF/modules");

        // get the list of all installed module with the "system-installed"
        // key set.  This is set on all modules installed by the system
        Map<String, Module> installed =
                mm.getInstalledModulesByKey(ModuleAttributes.SYSTEM_MODULE);

        // get the checksum of any module that has a checksum.  As a
        // side-effect, any module with a checksum is removed from the
        // list of installed modules, so that list can be used to decide
        // which modules to uninstall
        Map<String, String[]> installedChecksums = getChecksums(installed);

        // add all modules remaining in the installed list to the
        // uninstall list.  These are modules that were installed by an
        // old version of Wonderland and do not have a filename or
        // checksum attribute set.
        Collection<String> uninstall = new ArrayList<String>(installed.keySet());

        // now go through the checksums of old and new modules to determine
        // which modules need to be installed and which are unchanged
        List<TaggedModule> install = new ArrayList<TaggedModule>();
        for (Map.Entry<String, String> checksum : checksums.entrySet()) {

            // compare an existing checksum to an old checksum. If the
            // old checksum doesn't exist or is different than the new
            // checksum, install the new file.  This will overwrite the old
            // checksum in the process.
            String[] installedChecksum = installedChecksums.remove(checksum.getKey());
            if (installedChecksum == null ||
                    !installedChecksum[0].equals(checksum.getValue()))
            {
                install.add(createTaggedModule(checksum.getKey(),
                                               checksum.getValue(),
                                               moduleDir));
            }
        }

        // any modules not removed from the installedChecksums list are
        // old modules that were installed by a previous version of Wonderland
        // (not by the user) and aren't in the new module list.  We need to
        // remove these modules
        for (String[] moduleDesc : installedChecksums.values()) {
            uninstall.add(moduleDesc[1]);
        }

        // uninstall any modules on the uninstall list
        logger.warning("Uninstall: " + uninstall);
        mm.addToUninstall(uninstall);
       
        // install any modules on the install list
        String installList = "";
        for (TaggedModule tm : install) {
            installList += " " + tm.getFile().getName();
        }
        logger.warning("Install: " + installList);
        mm.addTaggedToInstall(install);
    }
View Full Code Here

            @FormParam("files[]") File file,
            @FormParam("files[]")FormDataContentDisposition info
            )
    {
        
        ModuleManager manager = ModuleManager.getModuleManager();
       
        String name = info.getFileName();
        System.out.println("file: "+name);
        if(name.endsWith(".jar")) {
            //success
            //parse out the '.jar'
            name = info.getFileName().substring(0,info.getFileName().length() - 4);
        } else {
            //fail
            logger.warning("FILE NOT A MODULE!");
            return Response.status(Status.INTERNAL_SERVER_ERROR).cacheControl(new CacheControl()).build();
        }
       
        File tmpFile = null;
        try {
            tmpFile = File.createTempFile(name+"_tmp", ".jar");
            tmpFile.deleteOnExit();
            RunUtil.writeToFile(new FileInputStream(file), tmpFile);
        } catch(Exception e) {
            logger.warning("ERROR WRITING TO FILE!");
            return Response.status(Status.INTERNAL_SERVER_ERROR).cacheControl(new CacheControl()).build();
        }
       
       
        Collection<File> moduleFiles = new LinkedList<File>();
        moduleFiles.add(tmpFile);
        Collection<Module> result = manager.addToInstall(moduleFiles);
        if(result.isEmpty()) {
            logger.warning("NOTHING IN MODULE!");
            return Response.status(Status.INTERNAL_SERVER_ERROR).cacheControl(new CacheControl()).build();
        }
       
View Full Code Here

    }
   
    @Path("/all")
    @GET
    public Response tryInstallAll() {
        ModuleManager manager = ModuleManager.getModuleManager();
        manager.installAll();
       
        return Response.ok().cacheControl(new CacheControl()).build();
    }
View Full Code Here

     * @return An XML encoding of the module's basic information
     */
    @GET
    @Produces({"application/xml", "application/json"})
    public Response getModuleList(@PathParam("state") String state) {
        ModuleManager manager = ModuleManager.getModuleManager();
        ModuleList moduleList = new ModuleList();
       
        /*
         * Check the state given, and fetch the modules. If the module state is
         * invalid, return a BAD_REQUEST error. Otherwise fetch the module list
         * according to the state and return a ModuleList object.
         */
        if (state == null) {
            return Response.status(Response.Status.BAD_REQUEST).build();
        }
        else if (state.equals("installed") == true) {
            Map<String, Module> modules = manager.getInstalledModules();

            // sort in dependecy order
            List<String> ordered = DeployManager.getDeploymentOrder(modules);

            // create the list of infos in the correct order
            Collection<ModuleInfo> list = new LinkedList();
            for (String moduleName : ordered) {
                Module module = modules.get(moduleName);
                list.add(module.getInfo());
            }

            moduleList.setModuleInfos(list.toArray(new ModuleInfo[] {}));
            return Response.ok(moduleList).build();
        }
        else if (state.equals("pending") == true) {
            Map<String, Module> modules = manager.getPendingModules();
            Collection<ModuleInfo> list = new LinkedList();
            Iterator<Map.Entry<String, Module>> it = modules.entrySet().iterator();
            while (it.hasNext() == true) {
                Map.Entry<String, Module> entry = it.next();
                list.add(entry.getValue().getInfo());
            }
            moduleList.setModuleInfos(list.toArray(new ModuleInfo[] {}));
            return Response.ok(moduleList).build();
        }
        else if (state.equals("uninstall") == true) {
            Map<String, ModuleInfo> modules = manager.getUninstallModuleInfos();
            Collection<ModuleInfo> list = new LinkedList();
            Iterator<Map.Entry<String, ModuleInfo>> it = modules.entrySet().iterator();
            while (it.hasNext() == true) {
                Map.Entry<String, ModuleInfo> entry = it.next();
                list.add(entry.getValue());
View Full Code Here

    public Response getModuleInfo(@PathParam("modulename") String moduleName) {
        /* Fetch thhe error logger for use in this method */
        Logger logger = ModuleManager.getLogger();
       
        /* Fetch the module from the module manager */
        ModuleManager manager = ModuleManager.getModuleManager();
        Module module = manager.getInstalledModules().get(moduleName);
        if (module == null) {
            /* Log an error and return an error response */
            logger.warning("ModuleManager: unable to locate module " + moduleName);
            ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
            return rb.build();
View Full Code Here

TOP

Related Classes of org.jdesktop.wonderland.modules.service.ModuleManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.