use of com.cosylab.acs.maci.BadParametersException in project ACS by ACS-Community.
the class ManagerImpl method getComponentInfo.
/**
* @see com.cosylab.acs.maci.Manager#getComponentInfo(int, int[], String, String, boolean)
*/
// TODO MF all (using wildchars match for domain names) interdomain queries
public ComponentInfo[] getComponentInfo(int id, int[] handles, String name_wc, String type_wc, boolean activeOnly) throws AcsJNoPermissionEx {
if (handles == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'handles' sequence expected.");
throw af;
} else if (handles.length == 0 && (name_wc == null || type_wc == null)) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'names_wc' or' type_wc' sequence expected.");
throw af;
}
/****************************************************************/
// the caller must have INTROSPECT_MANAGER access rights,
// or it must have adequate privileges to access the component (the same as with the get_component method).
securityCheck(id, AccessRights.NONE);
// info to be returned
ComponentInfo[] info = null;
// get info of requested handles
if (handles.length > 0) {
info = new ComponentInfo[handles.length];
for (int i = 0; i < handles.length; i++) {
// access rights to be checked here...
info[i] = getComponentInfo(handles[i]);
// filter out unavailable
if (info[i] != null && info[i].getComponent() == null)
info[i] = null;
}
} else // use name_wc and type_wc as search criteria
{
// check for inter-domain search
if (name_wc.startsWith(CURL_URI_SCHEMA)) {
URI curl = null;
try {
curl = CURLHelper.createURI(name_wc);
if (curl.getAuthority() != null && curl.getAuthority().indexOf('*') >= 0)
throw new IllegalArgumentException("Wildchars not supported in domain names.");
} catch (URISyntaxException e) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid CURL syntax in 'names_wc'.");
throw af;
}
name_wc = extractName(curl);
Manager remoteManager = null;
// if not local do inter-domain query
if (name_wc.startsWith(CURL_URI_SCHEMA)) {
// TODO MF do the login?
try {
String domainName = curl.getAuthority();
remoteManager = getManagerForDomain(domainName);
if (remoteManager == null)
throw new CoreException("Failed to obtain manager for domain '" + domainName + "'.");
} catch (Throwable th) {
logger.log(Level.WARNING, "Failed to obtain non-local manager required by CURL '" + curl + "'.", th);
return null;
}
}
try {
// local name to be used
String localName = curl.getPath();
if (localName.charAt(0) == '/')
localName = localName.substring(1);
ComponentInfo[] infos = remoteManager.getComponentInfo(INTERDOMAIN_MANAGER_HANDLE, handles, localName, type_wc, false);
if (infos != null) {
// prefix names
final String prefix = CURL_URI_SCHEMA + curl.getAuthority() + "/";
for (int i = 0; i < infos.length; i++) {
if (!infos[i].getName().startsWith(CURL_URI_SCHEMA))
infos[i].setName(prefix + infos[i].getName());
String containerName = infos[i].getContainerName();
if (containerName != null && !containerName.startsWith(CURL_URI_SCHEMA))
infos[i].setContainerName(prefix + containerName);
}
}
return infos;
} catch (Exception ex) {
RemoteException re = new RemoteException("Failed to obtain component infos for CURL '" + curl + "' from remote manager.", ex);
reportException(re);
return null;
}
}
// map of components to be returned
Map<String, ComponentInfo> map = new HashMap<String, ComponentInfo>();
// read active/registered components
componentsLock.lock();
try {
int h = components.first();
while (h != 0) {
ComponentInfo componentInfo = (ComponentInfo) components.get(h);
if (componentInfo.getComponent() != null && WildcharMatcher.match(name_wc, componentInfo.getName()) && WildcharMatcher.match(type_wc, componentInfo.getType())) {
// access rights to be checked here...
// found the match, add existing info to list
map.put(componentInfo.getName(), componentInfo);
}
h = components.next(h);
}
} finally {
componentsLock.unlock();
}
// add also non-active, if requested
if (!activeOnly) {
DAOProxy componentsDAO = getComponentsDAOProxy();
if (componentsDAO != null) {
try {
// get names of all components
/// @TODO here to check if CDB is available
componentsDAO.get_field_data("");
/*String[] ids =*/
String[] ids = getComponentsList();
// test names
for (int i = 0; i < ids.length; i++) {
// read name
//readStringCharacteristics(componentsDAO, ids[i]+"/Name");
String name = ids[i];
if (name == null) {
logger.log(Level.WARNING, "Misconfigured CDB, there is no name of component '" + ids[i] + "' defined.");
continue;
}
// add if not already added and matches criteria
if (!map.containsKey(name) && //!name.equals(ComponentSpec.COMPSPEC_ANY) &&
name.indexOf(ComponentSpec.COMPSPEC_ANY) != 0 && WildcharMatcher.match(name_wc, name)) {
// read type
String type = readStringCharacteristics(componentsDAO, ids[i] + "/Type");
if (type == null) {
logger.log(Level.WARNING, "Misconfigured CDB, there is no type of component '" + name + "' defined.");
continue;
}
// test type
if (!type.equals(ComponentSpec.COMPSPEC_ANY) && WildcharMatcher.match(type_wc, type)) {
// read code
String code = readStringCharacteristics(componentsDAO, ids[i] + "/Code");
if (code == null) {
logger.log(Level.WARNING, "Misconfigured CDB, there is no code of component '" + name + "' defined.");
continue;
}
// test code
if (code.equals(ComponentSpec.COMPSPEC_ANY))
continue;
// read container
String container = readStringCharacteristics(componentsDAO, ids[i] + "/Container");
if (container == null) {
logger.log(Level.WARNING, "Misconfigured CDB, there is no container name of component '" + name + "' defined.");
continue;
}
// test container
if (container.equals(ComponentSpec.COMPSPEC_ANY))
continue;
// got the match
// access rights to be checked here...
// create info and put it into list
ComponentInfo retInfo = new ComponentInfo(0, name, type, code, null);
retInfo.setContainerName(container);
map.put(name, retInfo);
}
}
}
} catch (Exception ex) {
CoreException ce = new CoreException("Failed to obtain component data from the CDB.", ex);
reportException(ce);
}
}
}
// copy to array
info = new ComponentInfo[map.size()];
map.values().toArray(info);
}
return info;
}
use of com.cosylab.acs.maci.BadParametersException in project ACS by ACS-Community.
the class ManagerImpl method getClientInfo.
/**
* @see com.cosylab.acs.maci.Manager#getClientInfo(int, int[], String)
*/
public ClientInfo[] getClientInfo(int id, int[] handles, String name_wc) throws AcsJNoPermissionEx {
if (handles == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'handles' sequence expected.");
throw af;
} else if (handles.length == 0 && name_wc == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'names_wc' sequence expected.");
throw af;
}
/*
Pattern pattern = null;
if (handles.length == 0 && name_wc != null)
{
// test wildcard patten (try to compile it)
try
{
pattern = Pattern.compile(name_wc);
}
catch (Exception ex)
{
// BAD_PARAM
BadParametersException af = new BadParametersException("Failed to compile 'names_wc' reqular expression string '"+name_wc+"'.");
af.caughtIn(this, "getClientInfo");
af.putValue("name_wc", name_wc);
throw af;
}
}
*/
/****************************************************************/
// info to be returned
ClientInfo[] info = null;
// requesting info. about itself
if (handles.length == 1 && handles[0] == id) {
// check handle, no special rights for own info
securityCheck(id, 0);
info = new ClientInfo[1];
info[0] = getClientInfo(id);
} else // get info of requested handles
if (handles.length > 0) {
// check handle, INTROSPECT_MANAGER rights needed
securityCheck(id, AccessRights.INTROSPECT_MANAGER);
info = new ClientInfo[handles.length];
for (int i = 0; i < handles.length; i++) info[i] = getClientInfo(handles[i]);
} else // get info requested using name wildcard
{
// check handle, INTROSPECT_MANAGER rights needed
securityCheck(id, AccessRights.INTROSPECT_MANAGER);
// list of clients matching search pattern
ArrayList<ClientInfo> list = new ArrayList<ClientInfo>();
// check clients
synchronized (clients) {
int h = clients.first();
while (h != 0) {
ClientInfo clientInfo = (ClientInfo) clients.get(h);
/*
Matcher m = pattern.matcher(clientInfo.getName());
if (m.matches())
*/
if (WildcharMatcher.match(name_wc, clientInfo.getName()))
list.add(clientInfo);
h = clients.next(h);
}
}
// check administrators
synchronized (administrators) {
int h = administrators.first();
while (h != 0) {
ClientInfo clientInfo = (ClientInfo) administrators.get(h);
/*
Matcher m = pattern.matcher(clientInfo.getName());
if (m.matches())
*/
if (WildcharMatcher.match(name_wc, clientInfo.getName()))
list.add(clientInfo);
h = administrators.next(h);
}
}
// copy to array
info = new ClientInfo[list.size()];
list.toArray(info);
}
return info;
}
use of com.cosylab.acs.maci.BadParametersException in project ACS by ACS-Community.
the class ManagerImpl method login.
/**
* @see com.cosylab.acs.maci.Manager#login(Client)
*/
public ClientInfo login(Client reference) throws AcsJNoPermissionEx {
// check if already shutdown
if (shutdown.get()) {
// already shutdown
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Manager in shutdown state.");
throw npe;
}
if (reference == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'reference' expected.");
throw af;
}
/****************************************************************/
ClientInfo info = null;
try {
long executionId = generateExecutionId();
AuthenticationData reply = reference.authenticate(executionId, "Identify yourself");
if (reply == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - non-null structure expected.");
throw af;
} else if (reply.getClientType() == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - non-null client type expected.");
throw af;
} else if (reply.getImplLang() == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - no-null implementation language expected.");
throw af;
}
// get client's name
String name = reference.name();
if (name == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::name()' method - non-null string expected.");
throw af;
}
logger.log(Level.FINE, "'" + name + "' is logging in.");
final long timeStamp = reply.getTimeStamp() > 0 ? reply.getTimeStamp() : System.currentTimeMillis();
if (reply.getExecutionId() != 0)
executionId = generateExecutionId();
// delegate
switch(reply.getClientType()) {
// container
case CONTAINER:
if (reference instanceof Container) {
info = containerLogin(name, reply, (Container) reference, timeStamp, executionId);
} else {
// NO_PERMISSION
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Given reply to 'Client::authenticate()' method indicated container login, but given reference does not implement 'maci::Container' interface.");
npe.setID(name);
throw npe;
}
break;
// client
case CLIENT:
info = clientLogin(name, reply, reference, timeStamp, executionId);
break;
// supervisor (administrator)
case ADMINISTRATOR:
if (reference instanceof Administrator) {
info = administratorLogin(name, reply, (Administrator) reference, timeStamp, executionId);
} else {
// NO_PERMISSION
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Given reply to 'Client::authenticate()' method indicated administrator login, but given reference does not implement 'maci::Administrator' interface.");
npe.setID(name);
throw npe;
}
break;
default:
assert (false);
}
} catch (AcsJNoPermissionEx npe) {
throw npe;
} catch (BadParametersException bpe) {
throw bpe;
} catch (NoResourcesException nre) {
throw nre;
} catch (RemoteException re) {
// TODO @todo exception
RuntimeException rt = new RuntimeException("Exception caught while examining the client. Login rejected.", re);
throw rt;
} catch (Throwable ex) {
// TODO @todo exception
RuntimeException rt = new RuntimeException("Unexpected exception during login. Login rejected.", ex);
throw rt;
}
/****************************************************************/
logger.log(Level.FINE, "Client with handle '" + HandleHelper.toString(info.getHandle()) + "' has logged in.");
return info;
}
use of com.cosylab.acs.maci.BadParametersException in project ACS by ACS-Community.
the class ManagerImpl method internalNoSyncReleaseComponent.
/**
* Internal method for releasing components.
*
* @param owner owner of the component.
* @param h handle of the component to be released.
* @param force force deactivate, if still has owners then component will be made unavailable.
* @return Number of clients that are still using the component after the operation completed.
*/
private ReleaseComponentResult internalNoSyncReleaseComponent(int owner, int h, boolean force) throws AcsJNoPermissionEx {
int handle = h & HANDLE_MASK;
int owners = 0;
ComponentInfo componentInfo = null;
componentsLock.lock();
try {
if (components.isAllocated(handle))
componentInfo = (ComponentInfo) components.get(handle);
if (componentInfo == null || componentInfo.getHandle() != h) {
// invalid component handle
BadParametersException af = new BadParametersException("Invalid component handle.");
throw af;
}
// remove ownership of the component
if (!componentInfo.getClients().contains(owner)) {
if (!force) {
// not an owner
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Unregistering component that client does not own.");
npe.setID(HandleHelper.toString(owner));
npe.setProtectedResource(componentInfo.getName());
throw npe;
}
} else {
// ACID - !!!
// remove client/component as an owner
executeCommand(new ComponentCommandClientRemove(componentInfo.getHandle() & HANDLE_MASK, owner));
// remove component from client component list
if (owner != this.getHandle())
removeComponentOwner(componentInfo.getHandle(), owner);
}
owners = componentInfo.getClients().size();
if (owners == 0) {
// there is not owner to be unavailable for
synchronized (unavailableComponents) {
if (unavailableComponents.containsKey(componentInfo.getName())) {
// !!! ACID
executeCommand(new UnavailableComponentCommandRemove(componentInfo.getName()));
//unavailableComponents.remove(componentInfo.getName());
}
}
}
} finally {
componentsLock.unlock();
}
/****************** component deactivation ******************/
ReleaseComponentResult result = new ReleaseComponentResult(owners, null);
// there is no owners of the component, deactivate it
if (force) {
try {
internalNoSyncDeactivateComponent(componentInfo);
} catch (Throwable th) {
result.exception = th;
}
} else if (owners == 0) {
int keepAliveTime = RELEASE_IMMEDIATELY;
String name = componentInfo.getName();
boolean isOtherDomainComponent = name.startsWith(CURL_URI_SCHEMA);
if (!isOtherDomainComponent) {
keepAliveTime = componentInfo.getKeepAliveTime();
if (keepAliveTime == RELEASE_TIME_UNDEFINED) {
// when info is passed from the container
DAOProxy dao = getComponentsDAOProxy();
if (dao != null)
keepAliveTime = readLongCharacteristics(dao, name + "/KeepAliveTime", RELEASE_IMMEDIATELY, true);
else
keepAliveTime = RELEASE_IMMEDIATELY;
}
}
if (keepAliveTime == 0) {
try {
internalNoSyncDeactivateComponent(componentInfo);
} catch (Throwable th) {
result.exception = th;
}
} else if (keepAliveTime > 0)
delayedDeactivationTask.schedule(new DeactivateComponentTask(name), keepAliveTime * 1000);
// negative means immortal, however this could not happen since immortal
// components have manager as an owner
}
/// TODO !!!!!!!!!!!!!! no more handle -> componentInfo data
// notify administrators about the release request
notifyComponentReleased(new int[] { owner }, new int[] { h }, System.currentTimeMillis());
logger.log(Level.FINE, "Component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") released.");
// component deactivated
if (owners == 0 || force) {
topologySortManager.notifyTopologyChange(componentInfo.getContainer());
} else if ((owner & TYPE_MASK) == COMPONENT_MASK) {
// component dependency changed...
// notify about the change (only if on the same container)...
// on complete system shutdown sort will be done anyway
ComponentInfo ownerComponentInfo = getComponentInfo(owner);
if (ownerComponentInfo != null && ownerComponentInfo.getContainerName() != null && ownerComponentInfo.getContainerName().equals(componentInfo.getContainerName()))
topologySortManager.notifyTopologyChange(componentInfo.getContainer());
}
return result;
}
use of com.cosylab.acs.maci.BadParametersException in project ACS by ACS-Community.
the class ManagerImpl method shutdownContainer.
/**
* @see com.cosylab.acs.maci.Manager#shutdownContainer(int, java.lang.String, int)
*/
public void shutdownContainer(int id, String containerName, int action) throws AcsJNoPermissionEx {
// check if null
if (containerName == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'containerName' expected.");
throw af;
}
/****************************************************************/
// the caller must have SHUTDOWN_SYSTEM access rights,
securityCheck(id, AccessRights.SHUTDOWN_SYSTEM);
Container container;
ContainerInfo containerInfo = getContainerInfo(containerName);
if (containerInfo == null || (container = containerInfo.getContainer()) == null) {
// NO_RESOURCES
NoResourcesException nre = new NoResourcesException("Container '" + containerName + "' not logged in.");
throw nre;
}
pendingContainerShutdown.add(containerInfo.getName());
try {
// release components
try {
// get shutdown order
ComponentInfo[] infos = topologySortManager.getComponentShutdownOrder(containerInfo);
releaseComponents(infos);
} catch (Throwable th) {
CoreException ce = new CoreException("Failed to release components on container '" + containerName + "'.", th);
reportException(ce);
}
// shutdown (or disconnect)
try {
if (action == 0)
container.disconnect();
else
container.shutdown(action);
} catch (Throwable th) {
// NO_RESOURCES
NoResourcesException nre = new NoResourcesException("Failed to shutdown container '" + containerName + "'.", th);
throw nre;
}
} finally {
pendingContainerShutdown.remove(containerInfo.getName());
}
/****************************************************************/
}
Aggregations