/** * Create a {@link ServiceElement}. * * @param deployment The {@link ServiceDeployment}, must not be {@code null}. * @return A {@code ServiceElement} * @throws ConfigurationException if there are problem reading the configuration */ public static ServiceElement create(final ServiceDeployment deployment) throws IOException, ConfigurationException, ResolverException, URISyntaxException { String configurationFilePath; if (Artifact.isArtifact(deployment.getConfig())) { logger.info("Resolve " + deployment.getConfig()); Resolver resolver = ResolverHelper.getResolver(); Artifact artifact = new Artifact(deployment.getConfig()); URL configLocation = resolver.getLocation(artifact.getGAV(), artifact.getType()); configurationFilePath = new File(configLocation.toURI()).getPath(); } else { configurationFilePath = deployment.getConfig(); } logger.info("Loading " + configurationFilePath); Configuration configuration = Configuration.getInstance(configurationFilePath); String component = "sorcer.core.provider.ServiceProvider"; String name = deployment.getName(); if (name == null) { name = configuration.getEntry(component, "name", String.class, null); } String[] interfaces = configuration.getEntry( "sorcer.core.exertion.deployment", "interfaces", String[].class, new String[0]); if (interfaces.length == 0 && deployment.getServiceType() != null) { interfaces = new String[] {deployment.getServiceType()}; } String[] codebaseJars = deployment.getCodebaseJars(); if (codebaseJars == null) { codebaseJars = configuration.getEntry( "sorcer.core.exertion.deployment", "codebaseJars", String[].class, new String[0]); } String[] implJars = deployment.getClasspathJars(); if (implJars == null) { implJars = configuration.getEntry( "sorcer.core.exertion.deployment", "implJars", String[].class, new String[0]); } String jvmArgs = deployment.getJvmArgs(); if (jvmArgs == null) { jvmArgs = configuration.getEntry("sorcer.core.exertion.deployment", "jvmArgs", String.class, null); } Boolean fork = deployment.getFork(); if (fork == null) { fork = configuration.getEntry( "sorcer.core.exertion.deployment", "fork", Boolean.class, Boolean.FALSE); } String architecture = deployment.getArchitecture(); if (architecture == null) { architecture = configuration.getEntry("sorcer.core.exertion.deployment", "arch", String.class, null); } String[] operatingSystems = deployment.getOperatingSystems(); if (operatingSystems.length == 0) { operatingSystems = configuration.getEntry( "sorcer.core.exertion.deployment", "opSys", String[].class, new String[0]); } String[] ips = deployment.getIps(); if (ips.length == 0) { ips = configuration.getEntry( "sorcer.core.exertion.deployment", "ips", String[].class, new String[0]); } String[] excludeIPs = deployment.getExcludeIps(); if (excludeIPs.length == 0) { excludeIPs = configuration.getEntry( "sorcer.core.exertion.deployment", "ips_exclude", String[].class, new String[0]); } String providerClass = configuration.getEntry( "sorcer.core.exertion.deployment", "providerClass", String.class, null); int maxPerNode = deployment.getMaxPerCybernode(); if (maxPerNode == 0) { maxPerNode = configuration.getEntry("sorcer.core.exertion.deployment", "perNode", int.class, 1); } String webster = configuration.getEntry("sorcer.core.exertion.deployment", "webster", String.class, null); ServiceDetails serviceDetails = new ServiceDetails( name, interfaces, codebaseJars, implJars, providerClass, jvmArgs, fork, maxPerNode, architecture, operatingSystems, ips, excludeIPs, webster); ServiceElement service = create(serviceDetails, deployment); if (logger.isDebugEnabled()) logger.debug( String.format( "Created ServiceElement\n=================\n%s\n=================\nFrom [%s]", service, deployment)); return service; }