use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.
the class ManagerImpl method makeComponentImmortal.
/**
* @see com.cosylab.acs.maci.Manager#makeComponentImmortal(int, java.net.URI, boolean)
*/
public void makeComponentImmortal(int id, URI curl, boolean immortalState) throws AcsJCannotGetComponentEx, AcsJNoPermissionEx, AcsJBadParameterEx {
// extract name
String name = extractName(curl);
// let same exception flying up
try {
checkCURL(curl);
} catch (AcsJBadParameterEx e) {
throw e;
}
// check handle and NONE permissions
securityCheck(id, AccessRights.NONE);
/****************************************************************/
int h;
ComponentInfo componentInfo = null;
componentsLock.lock();
try {
h = components.first();
while (h != 0) {
componentInfo = (ComponentInfo) components.get(h);
if (componentInfo.getName().equals(name)) {
h = componentInfo.getHandle();
break;
}
h = components.next(h);
}
// component not yet activated check
if (h == 0) {
NoResourcesException af = new NoResourcesException("Component not activated.");
throw af;
}
// if not an owner of the component, check administrator rights
if (!componentInfo.getClients().contains(id)) {
securityCheck(id, AccessRights.INTROSPECT_MANAGER);
}
if (immortalState) {
// finally, add manager as an owner
if (!componentInfo.getClients().contains(this.getHandle())) {
// ACID - !!!
executeCommand(new ComponentCommandClientAdd(componentInfo.getHandle() & HANDLE_MASK, this.getHandle()));
//componentInfo.getClients().add(this.getHandle());
}
logger.log(Level.INFO, "Component " + name + " was made immortal.");
}
} finally {
componentsLock.unlock();
}
// this must be done outside component sync. block
if (!immortalState) {
logger.log(Level.INFO, "Component " + name + " was made mortal.");
// finally, can happen that the manager is the only owner
// so release could be necessary
internalReleaseComponent(this.getHandle(), h, false);
}
/****************************************************************/
}
use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.
the class ManagerImpl method releaseComponentAsync.
/**
* @see com.cosylab.acs.maci.Manager#releaseComponentAsync(int, java.net.URI, com.cosylab.acs.maci.Manager.LongCompletionCallback)
*/
public void releaseComponentAsync(int id, URI curl, LongCompletionCallback callback) throws AcsJNoPermissionEx, AcsJBadParameterEx {
// throw up same exceptions
try {
checkCURL(curl);
} catch (AcsJBadParameterEx e) {
throw e;
}
// check handle and NONE permissions
securityCheck(id, AccessRights.NONE);
/****************************************************************/
// log info
final String requestorName = getRequestorName(id);
logger.log(Level.INFO, "'" + requestorName + "' requested async release of component '" + curl + "'.");
final int fid = id;
final URI fcurl = curl;
final boolean force = (id == this.getHandle());
final LongCompletionCallback fcallback = callback;
threadPool.execute(new Runnable() {
public void run() {
try {
ReleaseComponentResult rcr = internalReleaseComponent(fid, fcurl, force);
if (fcallback != null) {
if (rcr.exception == null) {
logger.log(Level.INFO, "Component '" + fcurl + "' async released by '" + requestorName + "'.");
fcallback.done(rcr.owners);
} else {
logger.log(Level.INFO, "Component '" + fcurl + "' async released by '" + requestorName + " with failure'.");
fcallback.failed(rcr.owners, rcr.exception);
}
}
} catch (Throwable th) {
if (fcallback != null)
fcallback.failed(-1, th);
}
}
});
}
use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.
the class ManagerImpl method getDynamicComponent.
/**
* @see com.cosylab.acs.maci.Manager#getDynamicComponent(int, com.cosylab.acs.maci.ComponentSpec, boolean)
*/
// TODO MF not supported
public ComponentInfo getDynamicComponent(int id, ComponentSpec componentSpec, boolean markAsDefault) throws AcsJCannotGetComponentEx, AcsJNoPermissionEx, AcsJIncompleteComponentSpecEx, AcsJInvalidComponentSpecEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
try {
// check if null
if (componentSpec == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec");
throw ex;
}
// check componentSpec components are null
if (componentSpec.getName() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Name");
throw ex;
}
if (componentSpec.getType() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Type");
throw ex;
}
if (componentSpec.getCode() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Code");
throw ex;
}
if (componentSpec.getContainer() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Container");
throw ex;
}
// check for empty componentSpec.name
if (componentSpec.getName().length() == 0) {
AcsJBadParameterEx ex = new AcsJBadParameterEx();
ex.setParameter("componentSpec.Name");
ex.setParameterValue("EMPTY");
ex.setReason("Non empty Component Name expected");
throw ex;
}
} catch (AcsJNullPointerEx e) {
AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx(e);
throw ex;
} catch (AcsJBadParameterEx e) {
AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx(e);
throw ex;
}
// check handle and NONE permissions
// Throws AcsJNoPermissionEx that is let flying up
securityCheck(id, AccessRights.NONE);
/****************************************************************/
// Same exceptions fly up
ComponentInfo componentInfo = null;
try {
componentInfo = internalRequestDynamicComponent(id, componentSpec);
} catch (AcsJSyncLockFailedEx e) {
AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
ex.setCURL(componentSpec.getName());
ex.setReason("Failed to get Synchronisation lock");
throw ex;
}
// update default components table
if (componentInfo != null && markAsDefault) {
synchronized (defaultComponents) {
// !!! ACID 3
executeCommand(new DefaultComponentCommandPut(componentInfo.getType(), componentInfo));
//defaultComponents.put(componentInfo.getType(), componentInfo.getName());
}
logger.log(Level.INFO, "'" + componentInfo.getName() + "' has been marked as a default component of type '" + componentInfo.getType() + "'.");
}
if (componentInfo == null) {
/**
* @todo Is it OK to get here? Always?
* This is a place where we have to check carefully.
*/
AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
ex.setCURL(componentSpec.getName());
throw ex;
}
return componentInfo;
}
use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.
the class ManagerImpl method getComponent.
/**
* @see #getComponent
*/
private Component getComponent(int id, URI curl, boolean activate, StatusHolder status, boolean allowServices) throws AcsJCannotGetComponentEx, AcsJNoPermissionEx {
AcsJCannotGetComponentEx ex2 = null;
// extract name
String name = extractName(curl);
// check if null
try {
checkCURL(curl);
} catch (AcsJBadParameterEx e) {
e.setParameter("curl");
ex2 = new AcsJCannotGetComponentEx(e);
ex2.setCURL(name);
throw ex2;
}
if (status == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("status");
ex2 = new AcsJCannotGetComponentEx(ex);
ex2.setCURL(name);
throw ex2;
}
/****************************************************************/
// log info
String requestorName = null;
if (id != 0) {
requestorName = getRequestorName(id);
logger.log(Level.INFO, "'" + requestorName + "' requested component '" + curl + "'.");
} else
logger.log(Level.INFO, "Request for component '" + curl + "' issued.");
// no login required for predefined objects (services)
Component component = null;
// "Manager" is a special service Component
if (allowServices && name.equals("Manager")) {
if (managerComponentReference != null)
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
else
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
component = new ServiceComponent(managerComponentReference);
} else // "NameService" is also a special service Component
if (allowServices && name.equals("NameService")) {
if (remoteDirectoryComponentReference != null)
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
else
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
component = new ServiceComponent(remoteDirectoryComponentReference);
} else if (allowServices && !name.startsWith(CURL_URI_SCHEMA) && isServiceComponent(name)) {
Object obj = lookup(name, null);
// set status
if (obj != null)
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
else
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
component = new ServiceComponent(obj);
} else {
// check handle and NONE permissions
securityCheck(id, AccessRights.NONE);
try {
component = internalRequestComponent(id, curl, status, activate);
} catch (Throwable ce) {
ex2 = new AcsJCannotGetComponentEx(ce);
}
}
// log info
if (component != null && component.getObject() != null) {
if (requestorName != null)
logger.log(Level.INFO, "Component '" + curl + "' provided to '" + requestorName + "'.");
else
logger.log(Level.INFO, "Component '" + curl + "' provided.");
} else if (ex2 == null && !activate && status.getStatus() == ComponentStatus.COMPONENT_NOT_ACTIVATED) {
if (requestorName != null)
logger.log(Level.INFO, "Request from '" + requestorName + "' for component '" + curl + "' completed sucessfully, but component not activated.");
else
logger.log(Level.INFO, "Request for component '" + curl + "' completed sucessfully, but component not activated.");
} else /**
* @todo GCH 2006.09.25
* This last case should never happen, because
* there should be and exception thrown instead.
*/
{
if (ex2 == null)
ex2 = new AcsJCannotGetComponentEx();
// it's clients responibility to handle the exception
if (requestorName != null) {
if (logger.isLoggable(Level.FINE))
logger.log(Level.WARNING, "Failed to provide component '" + curl + "' to '" + requestorName + "'.", ex2);
else
logger.log(Level.WARNING, "Failed to provide component '" + curl + "' to '" + requestorName + "'.");
} else {
if (logger.isLoggable(Level.FINE))
logger.log(Level.WARNING, "Failed to provide component '" + curl + "'.", ex2);
else
logger.log(Level.FINE, "Failed to provide component '" + curl + "'.");
}
}
if (ex2 != null) {
ex2.setCURL(name);
throw ex2;
}
return component;
}
use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.
the class ManagerImpl method getComponentNonSticky.
/**
* @see com.cosylab.acs.maci.Manager#getComponentNonSticky(int id, URI curl)
*/
public Component getComponentNonSticky(int id, URI curl) throws AcsJCannotGetComponentEx, AcsJNoPermissionEx {
// extract name
String name = extractName(curl);
// check if null
try {
checkCURL(curl);
} catch (AcsJBadParameterEx e) {
AcsJCannotGetComponentEx ex2 = new AcsJCannotGetComponentEx(e);
ex2.setCURL(name);
throw ex2;
}
/****************************************************************/
// check handle and NONE permissions
securityCheck(id, AccessRights.NONE);
// log info
String requestorName = getRequestorName(id);
logger.log(Level.FINE, "'" + requestorName + "' requested non-sticky component '" + curl + "'.");
Component component = null;
componentsLock.lock();
try {
int h = components.first();
while (h != 0) {
ComponentInfo ci = (ComponentInfo) components.get(h);
if (ci.getName().equals(name)) {
component = ci.getComponent();
break;
}
h = components.next(h);
}
} finally {
componentsLock.unlock();
}
// log info
if (component != null && component.getObject() != null)
logger.log(Level.FINE, "Non-sticky component '" + curl + "' provided to '" + requestorName + "'.");
else
logger.log(Level.INFO, "Failed to provide non-sticky component '" + curl + "' to '" + requestorName + "'.");
return component;
}
Aggregations