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