Deleting Old ServiceEndpoint instead of unpublishing

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@114689 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-05-06 14:52:15 +00:00
parent 65eda76918
commit 5d858f18f8
1 changed files with 19 additions and 15 deletions

View File

@ -27,6 +27,7 @@ import org.gcube.common.resources.gcore.ServiceEndpoint.Runtime;
import org.gcube.common.resources.gcore.common.Platform; import org.gcube.common.resources.gcore.common.Platform;
import org.gcube.common.resources.gcore.utils.Group; import org.gcube.common.resources.gcore.utils.Group;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.publisher.AdvancedScopedPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory; import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
import org.gcube.informationsystem.publisher.ScopedPublisher; import org.gcube.informationsystem.publisher.ScopedPublisher;
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException; import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
@ -139,19 +140,20 @@ public class SmartExecutorInitalizator extends ApplicationLifecycleHandler {
* @throws RegistryNotFoundException if the Registry is not found so the * @throws RegistryNotFoundException if the Registry is not found so the
* resource has not be published * resource has not be published
*/ */
private static void unPublishScopedResource(Resource resource, List<String> scopes) throws RegistryNotFoundException, Exception { private static void unPublishScopedResource(Resource resource) throws RegistryNotFoundException, Exception {
StringWriter stringWriter = new StringWriter(); //StringWriter stringWriter = new StringWriter();
Resources.marshal(resource, stringWriter); //Resources.marshal(resource, stringWriter);
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher(); ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
try { AdvancedScopedPublisher advancedScopedPublisher = new AdvancedScopedPublisher(scopedPublisher);
logger.debug("Trying to unpublish from {}:\n{}", scopes, stringWriter);
scopedPublisher.remove(resource, scopes); String id = resource.id();
logger.debug("Unpublish request executed successfully"); logger.debug("Trying to remove {} with ID from {}", resource.getClass().getSimpleName(), id, ScopeProvider.instance.get());
} catch (RegistryNotFoundException e) {
logger.error("The resource was not unpublished", e); //scopedPublisher.remove(resource, scopes);
throw e; advancedScopedPublisher.forceRemove(resource);
}
logger.debug("{} with ID {} removed successfully", resource.getClass().getSimpleName(), id);
} }
/** /**
@ -329,9 +331,7 @@ public class SmartExecutorInitalizator extends ApplicationLifecycleHandler {
try { try {
logger.debug("Trying to unpublish the old ServiceEndpoint with ID {} from scope {}", logger.debug("Trying to unpublish the old ServiceEndpoint with ID {} from scope {}",
serviceEndpoint.id(), scope); serviceEndpoint.id(), scope);
List<String> undeployScopes = new ArrayList<String>(); unPublishScopedResource(serviceEndpoint);
undeployScopes.add(scope);
unPublishScopedResource(serviceEndpoint, undeployScopes);
} catch(Exception e){ } catch(Exception e){
logger.debug("Exception tryng to unpublish the old ServiceEndpoint with ID {} from scope {}", logger.debug("Exception tryng to unpublish the old ServiceEndpoint with ID {} from scope {}",
serviceEndpoint.id(), scope, e); serviceEndpoint.id(), scope, e);
@ -410,7 +410,11 @@ public class SmartExecutorInitalizator extends ApplicationLifecycleHandler {
pool.shutdown(); pool.shutdown();
try { try {
unPublishScopedResource(serviceEndpoint, getScopes(ctx)); List<String> scopes = getScopes(ctx);
for(String scope : scopes){
ScopeProvider.instance.set(scope);
unPublishScopedResource(serviceEndpoint);
}
} catch (RegistryNotFoundException e) { } catch (RegistryNotFoundException e) {
logger.error("Unable to unpublish Service Endpoint.", e); logger.error("Unable to unpublish Service Endpoint.", e);
} catch (Exception e) { } catch (Exception e) {