@ -1,12 +1,12 @@
package org.gcube.informationsystem.publisher ;
import java.io.StringWriter ;
import java.util.Date ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.HashSet ;
import java.util.Iterator ;
import java.util.List ;
import java.util.Set ;
import java.util.UUID ;
import javax.xml.ws.soap.SOAPFaultException ;
@ -24,6 +24,7 @@ import org.gcube.informationsystem.publisher.scope.ValidatorProvider;
import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub ;
import org.gcube.informationsystem.publisher.stubs.registry.faults.CreateException ;
import org.gcube.informationsystem.publisher.stubs.registry.faults.InvalidResourceException ;
import org.gcube.informationsystem.publisher.stubs.registry.faults.ResourceDoesNotExistException ;
import org.gcube.informationsystem.publisher.stubs.registry.faults.ResourceNotAcceptedException ;
import org.gcube.informationsystem.publisher.stubs.registry.faults.UpdateException ;
import org.gcube.informationsystem.publisher.utils.RegistryStubs ;
@ -88,7 +89,6 @@ public class RegistryPublisherImpl implements RegistryPublisher {
log . debug ( "id generated: " + id ) ;
ResourceMediator . setId ( resource , id ) ;
}
HashSet < String > vosScopes = updateResourceScopes ( resource ) ;
// add the new scopes
for ( String scope : scopes ) {
log . debug ( "[VOCREATE] new scope added {}" , scope ) ;
@ -101,19 +101,20 @@ public class RegistryPublisherImpl implements RegistryPublisher {
log . error ( "the resource is not valid" , e ) ;
throw new IllegalArgumentException ( "the resource is not valid " , e . getCause ( ) ) ;
}
HashSet < String > vosScopes = updateResourceScopes ( resource ) ;
try {
if ( currentScope ! = null ) {
// checking the current scope: if the operation fails in the current VO it will give an exception, if it fails in another VO no exception will be given
String currentVO = Utils . getCurrentVO ( currentScope ) ;
if ( currentVO ! = null ) {
RegistryStub stub = getRegistryStub ( ) ;
createResource ( resource , currentVO , stub ) ;
vosScopes . remove ( currentVO ) ;
//in this case it is a root-vo scope so we need to create the resource only at root-vo level
createResource ( resource , currentVO , stub ) ;
vosScopes . remove ( currentVO ) ;
//in this case it is a root-vo scope so we need to create the resource only at root-vo level
} else {
RegistryStub stub = getRegistryStub ( ) ;
createResource ( resource , currentVO , stub ) ;
return resource ;
createResource ( resource , currentVO , stub ) ;
return resource ;
}
}
// update the resource for each VO
@ -232,17 +233,17 @@ public class RegistryPublisherImpl implements RegistryPublisher {
HashSet < String > vosScopes = Utils . getInternalVOScopes ( resource ) ;
try {
if ( currentScope ! = null ) {
// checking the current scope: if the operation fail in the current VO it will give an exception, if it fails in another VO no exception will be given
// checking the current scope: if the operation fail in the current VO it will raise an exception, if it fails in another VO no exception will be raised
String currentVO = Utils . getCurrentVO ( currentScope ) ;
if ( currentVO ! = null ) {
ScopeProvider . instance . set ( currentVO ) ;
registryUpdate ( resource , 0 ) ;
vosScopes . remove ( currentVO ) ;
// in this case it is a root-vo scope so we need to update the resource only at root-vo level
// in this case it is a root-vo scope
} else {
ScopeProvider . instance . set ( currentScope ) ;
registryUpdate ( resource , 0 ) ;
return resource ;
vosScopes . remove ( currentScope ) ;
}
}
@ -274,6 +275,66 @@ public class RegistryPublisherImpl implements RegistryPublisher {
return resource ;
}
/ * *
* The resource will be removed from all the scopes
* if the scope is the last scope in the resource , the profile will be deleted from IS else
* if it is a VRE scope then the profile will be updated without the VRE scope ,
* if it is a VO scope but there is another VRE scope , belong to the VO , defined in the resource then throw IllegalArgumentException
*
* @throws IllegalArgumentException if no service endpoints can be discovered or if there is another VRE scope defined in the resource
* /
public < T extends Resource > T vosRemove ( T resource , List < String > scopes ) {
String currentScope = ScopeProvider . instance . get ( ) ;
log . info ( " remove resource with id : {} from scope: {}" , resource . id ( ) , currentScope ) ;
ValidationUtils . valid ( "resource" , resource ) ; // helper that throws an IllegalArgumentException if resource are null
ValidationUtils . valid ( "scopes" , currentScope ) ; // helper that throws an IllegalArgumentException if scopes are null
validateScope ( resource ) ;
// the returned voScopes list is not used yet. it should be used if the update/remove operation will be done at VO level
// HashSet<String> vosScopes = updateResourceScopes(resource);
updateResourceScopes ( resource ) ;
try {
Resources . validate ( resource ) ;
} catch ( Exception e ) {
log . error ( "the resource is not valid" , e ) ;
throw new IllegalArgumentException ( "the resource is not valid" , e ) ;
}
log . info ( " remove {} scope from resource {}" , scopes , resource . id ( ) ) ;
Set < String > voScopesBeforeRemove = Utils . getInternalVOScopes ( resource ) ;
ResourceMediator . removeScope ( resource , scopes . toArray ( new String [ scopes . size ( ) ] ) ) ;
Set < String > voScopesAfterRemove = Utils . getInternalVOScopes ( resource ) ;
voScopesBeforeRemove . removeAll ( voScopesAfterRemove ) ;
for ( String scope : voScopesBeforeRemove )
try {
ScopeProvider . instance . set ( scope ) ;
log . info ( "remove from IS scope {}" , currentScope ) ;
registry . getStubs ( ) . remove ( resource . id ( ) , resource . type ( ) . toString ( ) ) ;
} catch ( ResourceDoesNotExistException e ) {
log . warn ( "resource not found in the current scope, continue" ) ;
} catch ( Exception e ) {
log . error ( "the resource can't be removed " , e ) ;
throw new IllegalArgumentException ( "the resource can't be removed from scope " + currentScope , e ) ;
} finally {
ScopeProvider . instance . set ( currentScope ) ;
}
// retrieves the scopes on resource and update it
// updateResource(resource, currentScope);
if ( ! voScopesAfterRemove . isEmpty ( ) )
try {
vosUpdate ( resource ) ;
} catch ( Exception e ) {
log . error ( "exception message: " + e . getMessage ( ) ) ;
throw new RuntimeException ( e . getMessage ( ) ) ;
}
return resource ;
}
/ * *
* The resource will be removed from current scope
* if the scope is the last scope in the resource , the profile will be deleted from IS else
@ -284,12 +345,12 @@ public class RegistryPublisherImpl implements RegistryPublisher {
* /
public < T extends Resource > T remove ( T resource ) {
String currentScope = ScopeProvider . instance . get ( ) ;
log . info ( " remove resource with id : "+ resource . id ( ) + " from scope: " + currentScope ) ;
log . info ( " remove resource with id : {} from scope: {}", resource . id ( ) , currentScope ) ;
ValidationUtils . valid ( "resource" , resource ) ; // helper that throws an IllegalArgumentException if resource are null
ValidationUtils . valid ( "scopes" , currentScope ) ; // helper that throws an IllegalArgumentException if scopes are null
validateScope ( resource ) ;
// the returned voScopes list is not used yet. it should be used if the update/remove operation will be done at VO level
// HashSet<String> vosScopes = updateResourceScopes(resource);
// the returned voScopes list is not used yet. it should be used if the update/remove operation will be done at VO level
// HashSet<String> vosScopes = updateResourceScopes(resource);
updateResourceScopes ( resource ) ;
try {
Resources . validate ( resource ) ;
@ -297,7 +358,7 @@ public class RegistryPublisherImpl implements RegistryPublisher {
log . error ( "the resource is not valid" , e ) ;
throw new IllegalArgumentException ( "the resource is not valid" , e ) ;
}
log . info ( " remove "+ currentScope + " scope from resource " + resource . id ( ) ) ;
log . info ( " remove {} scope from resource {}", currentScope , resource . id ( ) ) ;
ResourceMediator . removeScope ( resource , currentScope ) ;
// retrieves the scopes on resource and update it
// updateResource(resource, currentScope);
@ -312,6 +373,7 @@ public class RegistryPublisherImpl implements RegistryPublisher {
}
private void registryUpdate ( Resource resource , int tries ) {
log . trace ( "try to update resource with id: " + resource . id ( ) + " times " + ( tries + 1 ) + " on scope: " + ScopeProvider . instance . get ( ) ) ;
try {
@ -358,14 +420,14 @@ public class RegistryPublisherImpl implements RegistryPublisher {
* /
private < T extends Resource > void updateResourceRemoveOperation ( T resource , String currentScope ) {
if ( ! isRemoveNeeded ( resource , currentScope ) ) {
// updateResource(resource, currentScope);
// v 1.3 (20190902) try to update the resource just at vo level
// updateResource(resource, currentScope);
// v 1.3 (20190902) try to update the resource just at vo level
vosUpdate ( resource ) ;
} else { // remove the profile from IC
log . info ( "the resource have only the "+ currentScope + " scope defined. Remove the resource " + resource . id ( ) + " from IC" ) ;
log . info ( "the resource have only the {} scope defined. Remove the resource {} from IC", currentScope , resource . id ( ) ) ;
// if the resource hasn't any scope, the resource will be removed
try {
log . debug( "remove from IS scope " + currentScope ) ;
log . info( "remove from IS scope {}" , currentScope ) ;
registry . getStubs ( ) . remove ( resource . id ( ) , resource . type ( ) . toString ( ) ) ;
} catch ( Exception e ) {
log . error ( "the resource can't be removed " , e ) ;
@ -429,8 +491,7 @@ public class RegistryPublisherImpl implements RegistryPublisher {
ScopeProvider . instance . set ( currentScope ) ;
}
}
/ *
private < T extends Resource > void updateResourceVOLevel ( T resource , List < String > voScopes , String currentScope ) {
int tries = 0 ;
try {
@ -443,14 +504,17 @@ public class RegistryPublisherImpl implements RegistryPublisher {
ScopeProvider . instance . set ( currentScope ) ;
}
}
* /
private < T extends Resource > HashSet < String > updateResourceScopes ( T resource ) {
HashSet < String > vosScopes = Utils . getInternalVOScopes ( resource ) ;
// if the resource type is a RunningInstance or a HostingNode the check on the most recent resource is bypassed
if ( ( resource . type ( ) . toString ( ) . equalsIgnoreCase ( "RunningInstance" ) ) | | ( resource . type ( ) . toString ( ) . equalsIgnoreCase ( "GHN" ) ) | | ( resource . type ( ) . toString ( ) . equalsIgnoreCase ( "GCoreEndpoint" ) ) | | ( resource . type ( ) . toString ( ) . equalsIgnoreCase ( "HostingNode" ) ) )
return vosScopes ;
//extract the scopes from the more recent resource found at vo level
List < String > latestScopesFound = Utils . setLatestInternalScopes ( resource , vosScopes ) ;
log . debug ( "latest scope found are " + latestScopesFound ) ;
if ( ( latestScopesFound = = null ) | | ( latestScopesFound . isEmpty ( ) ) ) {
// if it is a new resource the latestScopesFound should be null, in this case the more recent scopes are the new scopes
// if it is a new resource the latestScopesFound should be null, in this case the more recent scopes are the new scopes
latestScopesFound = new ArrayList < String > ( vosScopes . size ( ) ) ;
for ( String scope : vosScopes ) {
latestScopesFound . add ( scope ) ;
@ -463,7 +527,7 @@ public class RegistryPublisherImpl implements RegistryPublisher {
log . debug ( "[VOCREATE] scope added {}" , scope ) ;
ResourceMediator . setScope ( resource , scope ) ;
ScopeBean scopeBean = new ScopeBean ( scope ) ;
// check if the scope was already present inside the resource, if not, it will be added to the voScopes
// check if the scope was already present inside the resource, if not, it will be added to the voScopes
if ( ( ! scopeBean . is ( Type . VRE ) ) & & ( ! vosScopes . contains ( scope ) ) ) {
vosScopes . add ( scope ) ;
}