/**************************************************************************** * This software is part of the gCube Project. * Site: http://www.gcube-system.org/ **************************************************************************** * The gCube/gCore software is licensed as Free Open Source software * conveying to the EUPL (http://ec.europa.eu/idabc/eupl). * The software and documentation is provided by its authors/distributors * "as is" and no expressed or * implied warranty is given for its use, quality or fitness for a * particular case. **************************************************************************** * Filename: RuntimeResourceManager.java **************************************************************************** * @author Massimiliano Assante ***************************************************************************/ package org.gcube.resourcemanagement.support.server.managers.resources; import java.io.StringReader; import org.gcube.common.core.contexts.GHNContext; import org.gcube.common.core.resources.GCUBEResource; import org.gcube.common.core.resources.GCUBERuntimeResource; import org.gcube.common.core.scope.GCUBEScope; import org.gcube.resourcemanagement.support.server.exceptions.AbstractResourceException; import org.gcube.resourcemanagement.support.server.exceptions.ResourceAccessException; import org.gcube.resourcemanagement.support.server.exceptions.ResourceOperationException; import org.gcube.resourcemanagement.support.server.exceptions.ResourceParameterException; import org.gcube.resourcemanagement.support.server.types.AllowedResourceTypes; import org.gcube.resourcemanagement.support.server.utils.Assertion; import org.gcube.resourcemanagement.support.server.utils.ServerConsole; import org.gcube.vremanagement.resourcemanager.stubs.binder.ResourceBinderPortType; import org.gcube.vremanagement.resourcemanager.stubs.reporting.ReportingPortType; /** * @author Massimiliano Assante (ISTI-CNR) * */ public class RuntimeResourceManager extends AbstractResourceManager { // Used internally to RuntimeResourceManager static functionalities (e.g. deploy). private static RuntimeResourceManager singleton = null; private static final String LOG_PREFIX = "[RR-MGR]"; static { if (RuntimeResourceManager.singleton == null) { try { RuntimeResourceManager.singleton = new RuntimeResourceManager("dummyservice", "dummyservice"); } catch (Exception e) { ServerConsole.error(LOG_PREFIX, e); } } } /** * @deprecated discouraged use. With no ID some operations cannot be accessed. */ public RuntimeResourceManager() throws ResourceParameterException, ResourceAccessException { super(AllowedResourceTypes.RuntimeResource); } public RuntimeResourceManager(final String id) throws ResourceParameterException, ResourceAccessException { super(id, AllowedResourceTypes.RuntimeResource); } public RuntimeResourceManager(final String id, final String name) throws ResourceParameterException, ResourceAccessException { super(id, name, AllowedResourceTypes.RuntimeResource); } public RuntimeResourceManager(final String id, final String name, final String subType) throws ResourceParameterException, ResourceAccessException { super(id, name, AllowedResourceTypes.RuntimeResource, subType); } public final String checkDeployStatus(final GCUBEScope scope, final String deployID) throws AbstractResourceException { Assertion checker = new Assertion(); checker.validate(scope != null, new ResourceParameterException("Invalid scope passed")); checker.validate(deployID != null && deployID.trim().length() > 0, new ResourceParameterException("Invalid reportID passed")); ReportingPortType vreManagerPortType = this.getReportResourceManager(scope); try { return vreManagerPortType.getReport(deployID); } catch (Exception e) { ServerConsole.error(LOG_PREFIX, e); throw new ResourceOperationException("Cannot retrieve the report: " + deployID + " " + e.getMessage()); } } @Override protected final GCUBEResource buildGCUBEResource(final String xmlRepresentation) throws AbstractResourceException { try { GCUBERuntimeResource impl = GHNContext.getImplementation(GCUBERuntimeResource.class); impl.load(new StringReader(xmlRepresentation)); return impl; } catch (Exception e) { throw new ResourceAccessException("Cannot load the stub for resource " + this.getType(), e); } } }