Search in sources :

Example 1 with NamingServiceDeployer

use of org.objectweb.proactive.extensions.dataspaces.core.naming.NamingServiceDeployer in project scheduling by ow2-proactive.

the class DataSpaceServiceStarter method startNamingService.

/**
 * StartNaming service and default file system server if needed.
 *
 * @throws Exception
 */
public void startNamingService() throws Exception {
    schedulerNode = PAActiveObject.getNode();
    localhostname = java.net.InetAddress.getLocalHost().getHostName();
    namingServiceDeployer = new NamingServiceDeployer(true);
    namingServiceURL = namingServiceDeployer.getNamingServiceURL();
    namingService = NamingService.createNamingServiceStub(namingServiceURL);
    // configure node for Data Spaces
    final BaseScratchSpaceConfiguration scratchConf = new BaseScratchSpaceConfiguration((String) null, DEFAULT_LOCAL_SCRATCH);
    DataSpacesNodes.configureNode(schedulerNode, scratchConf);
    // set default INPUT/OUTPUT spaces if needed
    PASchedulerProperties[][] confs = { { PASchedulerProperties.DATASPACE_DEFAULTINPUT_URL, PASchedulerProperties.DATASPACE_DEFAULTINPUT_LOCALPATH, PASchedulerProperties.DATASPACE_DEFAULTINPUT_HOSTNAME }, { PASchedulerProperties.DATASPACE_DEFAULTOUTPUT_URL, PASchedulerProperties.DATASPACE_DEFAULTOUTPUT_LOCALPATH, PASchedulerProperties.DATASPACE_DEFAULTOUTPUT_HOSTNAME }, { PASchedulerProperties.DATASPACE_DEFAULTGLOBAL_URL, PASchedulerProperties.DATASPACE_DEFAULTGLOBAL_LOCALPATH, PASchedulerProperties.DATASPACE_DEFAULTGLOBAL_HOSTNAME }, { PASchedulerProperties.DATASPACE_DEFAULTUSER_URL, PASchedulerProperties.DATASPACE_DEFAULTUSER_LOCALPATH, PASchedulerProperties.DATASPACE_DEFAULTUSER_HOSTNAME } };
    String[] spacesNames = { "DefaultInputSpace", "DefaultOutputSpace", "GlobalSpace", "UserSpaces" };
    String[] humanReadableNames = { "default INPUT space", "default OUTPUT space", "shared GLOBAL space", "USER spaces" };
    String[] default_paths = { DEFAULT_LOCAL_INPUT, DEFAULT_LOCAL_OUTPUT, DEFAULT_LOCAL_GLOBAL, DEFAULT_LOCAL_USER };
    for (int i = 0; i < confs.length; i++) {
        // variable used to precise exception
        String spaceDir = null;
        if (confs[i][0].isSet() && confs[i][0].getValueAsString().trim().isEmpty()) {
            logger.info("Unsetting property : " + confs[i][0].getKey());
            confs[i][0].unSet();
        }
        if (!confs[i][0].isSet()) {
            // if URL is set, if not we start a server ourselves
            try {
                logger.debug("Starting " + humanReadableNames[i] + " server...");
                if (!confs[i][1].isSet()) {
                    // check if the localpath is set, if not we use the default path
                    spaceDir = default_paths[i];
                    confs[i][1].updateProperty(spaceDir);
                } else {
                    // otherwise, we build a FileServer on the provided path
                    logger.debug("Using property-defined path at " + confs[i][1].getValueAsString());
                    spaceDir = confs[i][1].getValueAsString();
                }
                File dir = new File(spaceDir);
                if (!dir.exists()) {
                    dir.mkdirs();
                }
                FileSystemServerDeployer server = startServer(spacesNames[i], humanReadableNames[i], spaceDir);
                servers.add(server);
                confs[i][0].updateProperty(buildServerUrlList(server.getVFSRootURLs()));
                // use the hostname property if it is set, otherwise, use the local hostname
                if (!confs[i][2].isSet()) {
                    confs[i][2].updateProperty(localhostname);
                }
                logger.debug(humanReadableNames[i] + " server local path is " + spaceDir);
            } catch (IllegalArgumentException iae) {
                throw new IllegalArgumentException("Directory '" + spaceDir + "' cannot be accessed. Check if directory exists or if you have read/write rights.");
            }
        }
    }
    Set<SpaceInstanceInfo> predefinedSpaces = new HashSet<>();
    namingService.registerApplication(SchedulerConstants.SCHEDULER_DATASPACE_APPLICATION_ID, predefinedSpaces);
    serviceStarted = true;
    try {
        // register the Global space
        createSpace(SchedulerConstants.SCHEDULER_DATASPACE_APPLICATION_ID, SchedulerConstants.GLOBALSPACE_NAME, PASchedulerProperties.DATASPACE_DEFAULTGLOBAL_URL.getValueAsString(), PASchedulerProperties.DATASPACE_DEFAULTGLOBAL_LOCALPATH.getValueAsString(), localhostname, false, true);
    } catch (Exception e) {
        logger.error("", e);
    }
}
Also used : FileSystemServerDeployer(org.objectweb.proactive.extensions.vfsprovider.FileSystemServerDeployer) SpaceInstanceInfo(org.objectweb.proactive.extensions.dataspaces.core.SpaceInstanceInfo) FileSystemException(org.objectweb.proactive.extensions.dataspaces.exceptions.FileSystemException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) SpaceAlreadyRegisteredException(org.objectweb.proactive.extensions.dataspaces.exceptions.SpaceAlreadyRegisteredException) IOException(java.io.IOException) ProActiveException(org.objectweb.proactive.core.ProActiveException) NamingServiceDeployer(org.objectweb.proactive.extensions.dataspaces.core.naming.NamingServiceDeployer) File(java.io.File) BaseScratchSpaceConfiguration(org.objectweb.proactive.extensions.dataspaces.core.BaseScratchSpaceConfiguration) HashSet(java.util.HashSet)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1 ProActiveException (org.objectweb.proactive.core.ProActiveException)1 BaseScratchSpaceConfiguration (org.objectweb.proactive.extensions.dataspaces.core.BaseScratchSpaceConfiguration)1 SpaceInstanceInfo (org.objectweb.proactive.extensions.dataspaces.core.SpaceInstanceInfo)1 NamingServiceDeployer (org.objectweb.proactive.extensions.dataspaces.core.naming.NamingServiceDeployer)1 FileSystemException (org.objectweb.proactive.extensions.dataspaces.exceptions.FileSystemException)1 SpaceAlreadyRegisteredException (org.objectweb.proactive.extensions.dataspaces.exceptions.SpaceAlreadyRegisteredException)1 FileSystemServerDeployer (org.objectweb.proactive.extensions.vfsprovider.FileSystemServerDeployer)1