Package org.globus.workspace.service.impls.async

Examples of org.globus.workspace.service.impls.async.WorkspaceRequest


            requestContext.setLastInGroup(true);
            resource.setLastInGroup(false);
        }
        requestContext.setPartOfGroupRequest(resource.isPartOfGroupRequest());

        WorkspaceRequest req = null;
        int nextstate = STATE_INVALID;

        switch (current) {
            case STATE_DESTROY_SUCCEEDED:
                break;
            case STATE_DESTROY_FAILED:
                req = reqFactory.cancelAllAtVMM();
                nextstate = STATE_CANCELLING_AT_VMM;
                requestContext.setVm(resource.getVM());
                break;
            case STATE_STAGING_IN: // now unused
            case STATE_UNPROPAGATED:
                req = reqFactory.cancelUnpropagated();
                nextstate = STATE_CANCELLING_UNPROPAGATED;
                requestContext.setVm(resource.getVM());
                break;
            case STATE_PROPAGATING:
                req = reqFactory.cancelPropagating();
                nextstate = STATE_CANCELLING_PROPAGATING;
                requestContext.setVm(resource.getVM());
                break;
            case STATE_PROPAGATING_TO_START:
                req = reqFactory.cancelPropagatingToStart();
                nextstate = STATE_CANCELLING_PROPAGATING_TO_START;
                requestContext.setVm(resource.getVM());
                break;
            case STATE_PROPAGATING_TO_PAUSE:   
                req = reqFactory.cancelPropagatingToPause();
                nextstate = STATE_CANCELLING_PROPAGATING_TO_PAUSE;
                requestContext.setVm(resource.getVM());
                break;
            case STATE_PROPAGATED:
            case STATE_STARTING:
            case STATE_STARTED:
            case STATE_SERIALIZING:
            case STATE_SERIALIZED:
            case STATE_PAUSING:
            case STATE_PAUSED:
            case STATE_SHUTTING_DOWN:
                req = reqFactory.cancelAllAtVMM();
                nextstate = STATE_CANCELLING_AT_VMM;
                requestContext.setVm(resource.getVM());
                break;
            case STATE_READYING_FOR_TRANSPORT:
                req = reqFactory.cancelReadyingForTransport();
                nextstate = STATE_CANCELLING_READYING_FOR_TRANSPORT;
                requestContext.setVm(resource.getVM());
                break;
            case STATE_READY_FOR_TRANSPORT:
                req = reqFactory.cancelReadyForTransport();
                nextstate = STATE_CANCELLING_READY_FOR_TRANSPORT;
                requestContext.setVm(resource.getVM());
                break;
            case STATE_STAGING_OUT: // now unused
            default:
        }

        if (current >= STATE_CORRUPTED) {

            // currently we will try to do something about a workspace
            // corrupted at times that may have left image files or state
            // at the backend node, we do not handle other corrupt-*
            // situations now.

            final int oldstate = current - STATE_CORRUPTED;

            if (oldstate >= STATE_PROPAGATING
                    && oldstate < STATE_READYING_FOR_TRANSPORT) {

                req = reqFactory.cancelAllAtVMM();
                nextstate = STATE_CANCELLING_AT_VMM;
                requestContext.setVm(resource.getVM());

            } else {

                // candidate for admin log/trigger of severe issues

                final String err = "Destroying a corrupted " +
                            "resource in state '" + curStr +
                            "'. That state does not indicate files or " +
                            "cruft may be on VMM node, not doing anything" +
                            " (but there may be stray staged files off-VMM).";

                if (this.event) {
                    logger.info(Lager.ev(id) + err);
                } else if (this.trace) {
                    logger.trace(idStr + err);
                }
            }
        }

        if (req != null) {

            resource.setStateUnderLock(nextstate, null);
            requestContext.setNotify(STATE_DESTROYING);
            req.setRequestContext(requestContext);

            if (this.trace) {
                logger.trace("\n\n   ***** ST--remove: " + idStr
                                    + ", executing " + req.toString() + "\n");
            }

            try {
                destroy_lock.lockInterruptibly();
            } catch (InterruptedException e) {
                throw new ManageException(e.getMessage(), e);
            }

            lock.unlock();

            // TODO: add a timeout
            try {
                req.execute(); // could block
            } catch (Throwable t) {
                // candidate for admin log/trigger of severe issues
                logger.error("",t);
            } finally {
              try {
                  lock.lockInterruptibly();
                  destroy_lock.unlock();
              } catch (InterruptedException e) {
                  throw new ManageException(e.getMessage(), e);
              }
            }

            if (this.trace) {
                logger.trace("\n\n   ***** ST--remove: " + idStr
                              + ", done executing " + req.toString() + "\n");
            }

        } else {
            resource.setStateUnderLock(STATE_DESTROY_SUCCEEDED, null);
            if (this.trace) {
View Full Code Here


            }
            resource.setStateUnderLock(stateToSet, wexc);
            throw wexc;
        }

        WorkspaceRequest req;
        boolean fallback = false;
        final boolean propstartOK = resource.isPropagateStartOK();

        if (target == STATE_STARTED) {

            if (propstartOK) {
                req = this.reqFactory.propagateAndStart();

                if (req == null) {
                    if (this.trace) {
                        logger.trace("\n\n   ***** ST--propagate " + idStr +
                                ": could use propagateToStart, " +
                                            "but not implemented\n");
                    }
                    fallback = true;
                }

            } else {

                req = reqFactory.propagate();

                if (req == null) {

                    final String errMsg = "propagate functionality " +
                            "needed but it is not implemented";
                    final ManageException wexc =
                            new ManageException(errMsg);

                    resource.setStateUnderLock(
                                STATE_CORRUPTED + STATE_PROPAGATING, wexc);
                   
                    throw wexc;
                }

                // just change local var, not real resource target
                target = STATE_PROPAGATED;

                if (this.trace) {
                    logger.trace("\n\n   ***** ST--propagate " + idStr +
                    ": propagateToStart not OK for this resource, doing" +
                        " propagate-only\n");
                }

            }

        } else if (target == STATE_PAUSED) {

            if (propstartOK) {

                req = this.reqFactory.propagateAndPause();

                if (req == null) {
                    if (this.trace) {
                        logger.trace("\n\n   ***** ST--propagate " + idStr +
                       ": could use propagateToPause, but not implemented\n");
                    }
                    fallback = true;
                }

            } else {

                req = reqFactory.propagate();

                if (req == null) {

                    final String errMsg = "propagate functionality " +
                            "needed but it is not implemented";
                    final ManageException wexc =
                            new ManageException(errMsg);

                    resource.setStateUnderLock(
                                STATE_CORRUPTED + STATE_PROPAGATING, wexc);
                   
                    throw wexc;
                }

                // just change local var, not real resource target
                // todo: comment why
                target = STATE_PROPAGATED;

                if (this.trace) {

                    logger.trace("\n\n   ***** ST--propagate " + idStr +
                    ": propagateToPause not OK for this resource, doing" +
                        " propagate-only\n");
                }
            }

        } else if (target == STATE_PROPAGATED) {

            req = this.reqFactory.propagate();

            if (req == null) {

                final String errMsg = "propagate functionality " +
                            "needed but it is not implemented";
                final ManageException wexc =
                        new ManageException(errMsg);

                resource.setStateUnderLock(
                                STATE_CORRUPTED + STATE_PROPAGATING, wexc);

                throw wexc;
            }

        } else {

            // handlers before propagate handler should not
            // let this happen

            throw new ManageException("Current state is " +
                    this.dataConvert.stateName(current) + ", " +
                    "propagate is needed but not" +
                    " achieved, but target state is not " +
                    this.dataConvert.stateName(STATE_STARTED) + ", " +
                    this.dataConvert.stateName(STATE_PAUSED) + ", or" +
                    this.dataConvert.stateName(STATE_PROPAGATED) + ", it is " +
                    this.dataConvert.stateName(target));
        }

        if (fallback) {

            if (this.trace) {
                logger.trace("\n\n   ***** ST--propagate " + idStr +
                                        ": falling back to propagate-only\n");
            }

            req = reqFactory.propagate();

            if (req == null) {

                final String errMsg = "propagate functionality " +
                            "needed but it is not implemented";
                final ManageException wexc =
                        new ManageException(errMsg);

                resource.setStateUnderLock(
                                STATE_CORRUPTED + STATE_PROPAGATING, wexc);
               
                throw wexc;
            }

            // just change local var, not real resource target
            target = STATE_PROPAGATED;
        }


        final WorkspaceRequestContext requestContext =
                new WorkspaceRequestContext(id, resource.getName(),
                                            this.locator, this.lager);

        requestContext.setVm(resource.getVM());
        requestContext.setGroupID(resource.getGroupId());
        requestContext.setGroupSize(resource.getGroupSize());
        if (resource.isLastInGroup()) {
            requestContext.setLastInGroup(true);
            resource.setLastInGroup(false);
        }
        requestContext.setPartOfGroupRequest(resource.isPartOfGroupRequest());

        // req cannot be null here

        if (target == STATE_PROPAGATED) {

            requestContext.setNotify(STATE_PROPAGATED);
            req.setRequestContext(requestContext);

            resource.setStateUnderLock(STATE_PROPAGATING, null);

            if (this.trace) {
                logger.trace("\n\n   ***** ST--propagate " + idStr +
                        ": adding propagate request: " + req + "\n");
            }

            RequestDispatch.addRequest(req, id);
            return true;

        } else if (target == STATE_STARTED) {

            requestContext.setNotify(STATE_STARTED);
            req.setRequestContext(requestContext);

            resource.setStateUnderLock(STATE_PROPAGATING_TO_START, null);

            if (this.trace) {
                logger.trace("\n\n   ***** ST--propagate " + idStr +
                      ": adding propagate-to-start request: " + req + "\n");
            }

            RequestDispatch.addRequest(req, id);
            return true;

        } else {

            requestContext.setNotify(STATE_PAUSED);
            req.setRequestContext(requestContext);

            resource.setStateUnderLock(STATE_PROPAGATING_TO_PAUSE, null);

            if (this.trace) {
                logger.trace("\n\n   ***** ST--propagate " + idStr +
View Full Code Here

        // no implementation of these does not cause resource to move to
        // corrupted which is why TaskNotImplementedException is thrown

        boolean notifyPaused = false;

        final WorkspaceRequest req;

        if (target == STATE_REBOOT) {

            req = this.reqFactory.reboot();

            if (req == null) {
                throw new TaskNotImplementedException("reboot not implemented");
            }

            // would be cool to implement a 'reboot -> start-paused' option,
            // (there may be a conceivable application use), but for now we
            // expect reboot results in STATE_STARTED
            resource.setTargetStateUnderLock(STATE_STARTED);

            if (this.trace) {
                logger.trace("\n\n   ***** ST--start " + idStr +
                        ": adding reboot request: " + req + "\n");
            }

        } else if (current == STATE_PAUSED) {

            if (target == STATE_PAUSED) {
                throw new ProgrammingError("current and target are " +
                        "both paused");
            }

            req = reqFactory.unpause();

            if (req == null) {
                throw new TaskNotImplementedException(
                                        "unpause not implemented");
            }

            if (this.trace) {
                logger.trace("\n\n   ***** ST--start " + idStr +
                        ": adding unpause request: " + req + "\n");
            }

        } else if (current == STATE_PROPAGATED) {

            if (target == STATE_PAUSED) {
                req = reqFactory.startPaused();
                notifyPaused = true;
            } else {
                req = reqFactory.start();
            }

            if (req == null) {
                throw new TaskNotImplementedException(
                                        "start (create) not implemented");
            }

            if (this.trace) {
                logger.trace("\n\n   ***** ST--start " + idStr +
                        ": adding start (create) request: " + req + "\n");
            }

        } else if (current == STATE_SERIALIZED) {

            req = reqFactory.unserialize();

            if (req == null) {
                throw new TaskNotImplementedException(
                                        "unserialize not implemented");
            }

            if (this.trace) {
                logger.trace("\n\n   ***** ST--start " + idStr +
                        ": adding unserialize request: " + req + "\n");
            }

        } else {
            // If current is another state between STATE_PROPAGATED and
            // STATE_SHUTTING_DOWN, there is nothing to do but wait until
            // the notification comes in that STATE_PROPAGATED,
            // STATE_PAUSED, or STATE_SERIALIZED has been achieved.

            // If target is still STATE_STARTED at that point, StateTransition
            // will run again via WorkspaceResourceImpl.setState() and will
            // cause one of the three commands to be launched

            return true;
        }

        final WorkspaceRequestContext requestContext =
                new WorkspaceRequestContext(id, resource.getName(),
                                            this.locator, this.lager);

        requestContext.setVm(resource.getVM());
        if (notifyPaused) {
            requestContext.setNotify(STATE_PAUSED);
        } else {
            requestContext.setNotify(STATE_STARTED);
        }
        requestContext.setGroupID(resource.getGroupId());
        requestContext.setGroupSize(resource.getGroupSize());
        if (resource.isLastInGroup()) {
            requestContext.setLastInGroup(true);
            resource.setLastInGroup(false);
        }
        requestContext.setPartOfGroupRequest(resource.isPartOfGroupRequest());
        req.setRequestContext(requestContext);

        resource.setStateUnderLock(STATE_STARTING, null);
        RequestDispatch.addRequest(req, id);

        return true;
View Full Code Here

            logger.trace("\n\n   ***** ST--shutdown: processing " +
                    idStr + ", current = " + curStr + ", target = " +
                    tarStr + "\n");
        }

        final WorkspaceRequest req;

        final WorkspaceRequestContext requestContext =
                new WorkspaceRequestContext(id, resource.getName(),
                                            this.locator, this.lager);

        if (target == STATE_PROPAGATED ||
            target == STATE_READY_FOR_TRANSPORT ||
            target == STATE_STAGED_OUT) {

            req = reqFactory.shutdownNormal();

            if (req == null) {
                throw new TaskNotImplementedException(
                                    "shutdown normal unimplemented");
            }

            requestContext.setNotify(STATE_PROPAGATED);
            resource.setStateUnderLock(STATE_SHUTTING_DOWN, null);

            if (this.trace) {
                logger.trace("\n\n   ***** ST--shutdown " + idStr +
                        ": target state is " + tarStr +
                        ", adding shutdown-normal request: " + req + "\n");
            }


        } else if (target == STATE_PAUSED) {

            if (current == STATE_PAUSING) {
                return true;
            }

            // current == STATE_PAUSED guaranteed to be false, so we are
            // just left with STATE_STARTING and STATE_STARTED

            req = reqFactory.pause();

            if (req == null) {
                throw new TaskNotImplementedException("pause not implemented");
            }

            requestContext.setNotify(STATE_PAUSED);
            resource.setStateUnderLock(STATE_PAUSING, null);

            if (this.trace) {
                logger.trace("\n\n   ***** ST--shutdown " + idStr +
                        ": target state is " + tarStr +
                        ", adding pause request: " + req + "\n");
            }

        } else {

            req = reqFactory.shutdownSerialize();

            if (req == null) {
                throw new TaskNotImplementedException(
                                    "shutdown-serialize not implemented");
            }

            requestContext.setNotify(STATE_PROPAGATED);
            resource.setStateUnderLock(STATE_SERIALIZING, null);

            if (this.trace) {
                logger.trace("\n\n   ***** ST--shutdown " + idStr +
                        ": target state is " + tarStr +
                        ", adding serialize request: " + req + "\n");
            }
        }

        requestContext.setVm(resource.getVM());
        requestContext.setGroupID(resource.getGroupId());
        requestContext.setGroupSize(resource.getGroupSize());
        if (resource.isLastInGroup()) {
            requestContext.setLastInGroup(true);
            resource.setLastInGroup(false);
        }
        requestContext.setPartOfGroupRequest(resource.isPartOfGroupRequest());
        req.setRequestContext(requestContext);
        RequestDispatch.addRequest(req, id);

        return true;
    }
View Full Code Here

            }
            resrc.setStateUnderLock(stateToSet, wexc);
            throw wexc;
        }

        final WorkspaceRequest req = this.reqFactory.readyForTransport();
        if (req == null) {

            final String errMsg = "ready-for-transport " +
                    "functionality needed and enabled but no implementation " +
                        "class is configured";
            final ManageException wexc =
                    new ManageException(errMsg);

            final int stateToSet;
            if (corrupTag == STATE_INVALID) {
                stateToSet = STATE_CORRUPTED_GENERIC;
            } else {
                stateToSet = STATE_CORRUPTED + corrupTag;
            }
            resrc.setStateUnderLock(stateToSet, wexc);
            throw wexc;
        }

        final WorkspaceRequestContext requestContext =
                new WorkspaceRequestContext(id, resrc.getName(),
                                            this.locator, this.lager);

        requestContext.setVm(resrc.getVM());
        requestContext.setNotify(STATE_READY_FOR_TRANSPORT);
        req.setRequestContext(requestContext);

        resrc.setStateUnderLock(STATE_READYING_FOR_TRANSPORT, null);

        if (this.trace) {
            logger.trace("\n\n   ***** ST--rForT " + idStr +
View Full Code Here

TOP

Related Classes of org.globus.workspace.service.impls.async.WorkspaceRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.