Package xcat.exceptions

Examples of xcat.exceptions.NonstandardException


     
      // set autocommit to false so that all of the following is atomic
      conn.setAutoCommit(false);
    } catch (Exception e) {
      logger.severe("Error while connecting to database", e);
      throw new NonstandardException("Error while connecting to database", e);
    }

    try {
      // for every ComponentInfo, add one insert statement
      for (int i = 0; i < componentInfo.length; i++) {
  String sqlStmt =
    "insert into coordinator_table(instance_name, " +
    "instance_location, creation_proto, component_xml, " +
    "instance_handle, application_id) values (" +
    "'" + componentInfo[i].getInstanceName() + "', " +
    "'" + componentInfo[i].getInstanceLocation() + "', " +
    "'" + componentInfo[i].getCreationProto() + "', " +
    "'" + componentInfo[i].getComponentXML() + "', " +
    "'" + componentInfo[i].getInstanceHandle() + "', " +
    "'" + applicationID + "');";
  PreparedStatement stmt = conn.prepareStatement(sqlStmt);
  stmt.executeUpdate();
      }
     
      // add a single entry into the application map table
      String sqlStmt =
  "insert into app_map_table(application_id, application_name) values " +
  "('" + applicationID + "', '" + applicationName + "');";
      PreparedStatement stmt = conn.prepareStatement(sqlStmt);
      stmt.executeUpdate();

      // commit all inserts
      conn.commit();

      // clean up
      conn.close();
    } catch (Exception e) {
      logger.severe("Error while trying to store state into database: " +
        " Trying to rollback", e);
     
      // try to rollback
      try {
  conn.rollback();
      } catch (Exception re) {
  logger.severe("Error while trying to store state into database: " +
          " Rollback failed", re);
  throw new NonstandardException("Error while trying to store state into database: " +
               " Rollback failed", re);
      }

      throw new NonstandardException("Error while trying to store state into database: " +
             " Rollback successful", e);
    }
  }
View Full Code Here


           ComponentInfo componentInfo)
    throws gov.cca.CCAException {
    logger.finest("called with component name: " + componentName);

    if (componentMap.containsKey(componentName))
      throw new NonstandardException("Component " + componentName +
             " already exists");

    // add the ComponentInfo for this component
    componentMap.put(componentName, componentInfo);
View Full Code Here

    throws gov.cca.CCAException {
    logger.finest("called with uses component: " + usesComponentName +
      " and provides component: " + providesComponentName);

    if (!componentMap.containsKey(usesComponentName))
      throw new NonstandardException("Component " + usesComponentName +
             " not present in the graph");
    if (!componentMap.containsKey(providesComponentName))
      throw new NonstandardException("Component " + providesComponentName +
             " not present in the graph");

    // retrieve componentIDs for the uses and provides side
    MobileComponentID userID =
      new MobileComponentIDClientImpl(usesComponentName,
View Full Code Here

    XCATComponentIDClientImpl cid =
      (XCATComponentIDClientImpl) namedComponentIDs.get(instanceName);

    if (cid == null)
      throw new NonstandardException("Instance name : " + instanceName +
             " is unknown");

    synchronized(cid) {
     
      // set the GSH for the ComponentIDClient
View Full Code Here

             String masterStorageServiceURL)
    throws gov.cca.CCAException {

    // Retrieve information for this component
    if (!componentMap.containsKey(componentName))
      throw new NonstandardException("Unknown component: " + componentName);
    ComponentInfo cInfo = (ComponentInfo) componentMap.get(componentName);
   
    // create empty connection list if entry for this component doesn't exist
    if (!connectionMap.containsKey(componentName)) {
      Vector connIDs = new Vector();
      connectionMap.put(componentName, connIDs);
    }

    // Get a list of connections for this component
    Vector connIDs = (Vector) connectionMap.get(componentName);
   
    // Send migration requests to all connected components
    int numConns = connIDs.size();
    logger.finest("found " + numConns + " connection " +
      "for component " + componentName);
   
    // create an entry into the migrationMap
    MigrationInfo mInfo = new MigrationInfo(numConns);
    migrationMap.put(componentName, mInfo);
   
    for (int i = 0; i < numConns; i++) {
      XCATConnectionID connID = (XCATConnectionID) connIDs.get(i);
      MobileComponentID userID = (MobileComponentID) connID.getUser();
     
      userID.requestMigration(componentName,
            connID.getUserPortName(),
            getGSH());
    }
   
    // Wait till all users are OK with migration
    synchronized(mInfo) {
      if (mInfo.getApprovedUsers() < numConns) {
  try {
    mInfo.wait();
  } catch (InterruptedException ie) {
    logger.severe("Exception when waiting for uses sides to approve migration",
      ie);
    throw new NonstandardException("Exception when waiting for migration approval",
           ie);
  }
      }
    }

    // check if the above call was successful
    if (mInfo.getMigrationStatus() == AppCoordinatorCallback.EXCEPTION)
      throw new NonstandardException("Remote side did not approve migration");

    // Confirm to all users that provider is migrating
    for (int i = 0; i < numConns; i++) {
      XCATConnectionID connID = (XCATConnectionID) connIDs.get(i);
      MobileComponentID userID = (MobileComponentID) connID.getUser();
      userID.confirmMigration(connID.getUserPortName());
    }
   
    // Freeze the execution of the component
    MobileComponentID cid =
      new MobileComponentIDClientImpl(cInfo.getInstanceName(),
              cInfo.getInstanceHandle());
    cid.freezeComponent(getGSH());
   
    // Wait till the component sends back a notification that it is frozen
    synchronized(mInfo) {
      if (!mInfo.getIsFrozen()) {
  try {
    mInfo.wait();
  } catch (InterruptedException ie) {
    logger.severe("Exception when waiting for migration to complete",
      ie);
    throw new NonstandardException("Exception when waiting for migration to complete",
           ie);
  }
      }
    }
   
    // decrement number of outstanding frozen components
    synchronized(this) {
      outstandingFrozenComps--;
    }

    // check if the above call was successful
    if (mInfo.getMigrationStatus() == AppCoordinatorCallback.EXCEPTION)
      throw new NonstandardException("Remote component threw exception while being frozen");

    // Store the individual component state into persistent storage
    MasterStorageService mss = (MasterStorageService)
      URLToReference.createReference(masterStorageServiceURL,
             MasterStorageService.class.getName());
    String individualStorageServiceURL = mss.getIndividualStorageServiceLocation();
    String storageID = cid.storeIndividualComponentState(individualStorageServiceURL);

    // destroy the remote component
    try {
      cid.destroy();
    } catch (Exception e) {
      logger.severe("Caught exception while trying to destroy component",
        e);
      throw new NonstandardException("Caught exception while trying to destroy component",
             e);
    }

    // create a new instance of the component at the specified location
    cInfo.setInstanceLocation(targetLocation);
View Full Code Here

   */
  public String getGSH()
    throws gov.cca.CCAException {
    logger.finest("called");
    if (builderGSH == null)
      throw new NonstandardException("GSH for this port is not set");
    return builderGSH;
  }
View Full Code Here

        (ComponentStaticInformation)Unmarshaller.unmarshal
        (ComponentStaticInformation.class, readerCompStaticInfo);
      executionEnvList = compStaticInfo.getExecutionEnv();
    } catch (Exception e) {
      logger.severe("Exception thrown while parsing Component XML", e);
      throw new NonstandardException("Exception while parsing Component XML", e);
    }

    // create a new TypeMap and fill in the values
    TypeMap componentEnv = new TypeMapImpl();
    componentEnv.putString("execHost", cInfo.getInstanceLocation());
    componentEnv.putString("creationProto", cInfo.getCreationProto());

    // check if a valid installation exists for this host/proto
    boolean found = false;
    for (int k = 0; k < executionEnvList.length; k++) {
      ExecutionEnv executionEnv = executionEnvList[k];
      String[] hostName = executionEnv.getHostName();
      String[] creationMech = executionEnv.getCreationProto();

      // check if there is a match for the hostName
      int h;
      for (h = 0; h < hostName.length; h++) {
  if (hostName[h].equals(cInfo.getInstanceLocation())) {
    break;
  }
      }

      // if h equals hostName.length, then skip
      if (h == hostName.length)
  continue;
     
      // check if there is a match for creationProto
      int m;
      for (m = 0; m < creationMech.length; m++) {
  if (creationMech[m].equals(cInfo.getCreationProto())) {
    break;
  }
      }

      // if h equals creationMech.length, then skip
      if (m == creationMech.length)
  continue;
     
      // if we get here, this is a valid installation for this
      // creationProto/execHost pair
      NameValuePair[] nameValuePairList =
  executionEnv.getNameValuePair();
      for (int l = 0; l < nameValuePairList.length; l++) {
  NameValuePair nameValuePair = nameValuePairList[l];
  String nameOfVariable = nameValuePair.getName();
  String value = nameValuePair.getValue();
  componentEnv.putString(nameOfVariable, value);
      }
     
      // found an installation, break here
      found = true;
      break;
    }
   
    // if no valid installation found, throw an Exception
    if (!found) {
      String message = new String ("No valid installation for : " +
           cInfo.getInstanceLocation() + " , " +
           cInfo.getCreationProto());
      logger.severe(message);
      throw new NonstandardException(message);
    }

    // get the name of the class for the component
    String className = componentEnv.getString("className",
               "None");
    if (className.equals("None"))
      throw new NonstandardException("Property className for component not defined");
   
    // notify that this is a migration
    componentEnv.putString("componentHandle", cInfo.getInstanceHandle());
    componentEnv.putBool("isMigrated", true);

    // invoke the Builder Service to create a new instance
    XCATBuilderService builderService = null;
    try {
      builderService = new XCATBuilderServiceImpl(false);
    } catch (Exception e) {
      logger.severe("Can't instantiate Builder service", e);
      throw new NonstandardException("Can't instantiate Builder service", e);
    }
    String builderGSH = HandleResolver.createGSH("coordinatorbuilderService");
    builderService.setGSH(builderGSH);
    HandleResolver.addReference(builderGSH, builderService);
    builderService.createInstance(cInfo.getInstanceName(),
View Full Code Here

   */
  public void setGSH(String handle)
    throws gov.cca.CCAException {
    logger.finest("called with handle: " + handle);
    if (builderGSH != null)
      throw new NonstandardException("GSH for this port is already set");
    builderGSH = handle;
  }
View Full Code Here

  try {
    wait();
  } catch (InterruptedException ie) {
    logger.severe("Exception when waiting for component to be frozen",
      ie);
    throw new NonstandardException("Exception when waiting for component to be frozen",
           ie);
  }

  // set the number of outstanding frozen components to 0
  outstandingFrozenComps = 0;

  // check if the above call was successful
  if (checkpointStatus == AppCoordinatorCallback.EXCEPTION)
    throw new NonstandardException("Exception while freezing components");
      }
    }
    long time2 = System.currentTimeMillis();
    logger.info("Time for components to freeze: " + (time2 - time1));

    // send request to store the state of the components
    MasterStorageService mss = (MasterStorageService)
      URLToReference.createReference(masterStorageServiceURL,
             MasterStorageService.class.getName());
    for (int i = 0; i < componentList.length; i++) {
      String individualStorageServiceURL = mss.getIndividualStorageServiceLocation();
      ComponentInfo cInfo = (ComponentInfo) componentList[i];
      MobileComponentID cid =
  new MobileComponentIDClientImpl(cInfo.getInstanceName(),
          cInfo.getInstanceHandle());
      cid.appendStateToCheckpoint(individualStorageServiceURL, getGSH());
    }

    // wait till all components have stored their states
    if (numComponentsStateStored < componentList.length) {
      synchronized(this) {
  try {
    wait();
  } catch (InterruptedException ie) {
    logger.severe("Exception when waiting for components to store states",
      ie);
    throw new NonstandardException("Exception when waiting for components to store states",
           ie);
  }

  // set the number of outstanding frozen components to 0
  numComponentsStateStored = 0;

  // check if the above call was successful
  if (checkpointStatus == AppCoordinatorCallback.EXCEPTION)
    throw new NonstandardException("Exception while storing component state");
      }
    }
    long time3 = System.currentTimeMillis();
    logger.info("Storing checkpoints: " + (time3 - time2));

    // Atomically update locations of checkpoints in the database
    Hashtable oldCheckpointMap = checkpointMap;
    checkpointMap = tempCheckpointMap;
    tempCheckpointMap = new Hashtable();
    if (dburl != null) {
      // Commit component information into database
      Connection conn = null;
      try {
  // connect to the database
  conn = DriverManager.getConnection(dburl,
             dbuser,
             dbpasswd);
 
  // set autocommit to false so that all of the following is atomic
  conn.setAutoCommit(false);
      } catch (Exception e) {
  logger.severe("Error while connecting to database", e);
  throw new NonstandardException("Error while connecting to database", e);
      }

      try {
  // for every component, update the distributed_checkpoint_table
  for (int i = 0; i < componentList.length; i++) {
    ComponentInfo cInfo = (ComponentInfo) componentList[i];
    CheckpointInfo cpInfo =
      (CheckpointInfo) checkpointMap.get(cInfo.getInstanceName());

    // update the entry into the table
    // have to delete + insert since MySQL 4.0.x doesn't support
    // ON DUPLICATE KEY UPDATE
    String sqlStmt0 =
      "delete from distributed_checkpoint_table where " +
      "instance_handle = '" +  cInfo.getInstanceHandle() + "';";
    PreparedStatement stmt0 = conn.prepareStatement(sqlStmt0);
    stmt0.executeUpdate();

    String sqlStmt1 =
      "insert into distributed_checkpoint_table" +
      "(instance_handle, application_id, " +
      "individual_storage_service_url, " +
      "storage_id) values (" +
      "'" + cInfo.getInstanceHandle() + "', " +
      "'" + applicationID + "', " +
      "'" + cpInfo.getStorageServiceURL() + "', " +
      "'" + cpInfo.getStorageID() + "');";
    PreparedStatement stmt1 = conn.prepareStatement(sqlStmt1);
    stmt1.executeUpdate();
  }
   
  // commit all inserts
  conn.commit();
 
  // clean up
  conn.close();
      } catch (Exception e) {
  logger.severe("Error while trying to store checkpoint locations into database: " +
          " Trying to rollback", e);
 
  // try to rollback
  try {
    conn.rollback();
  } catch (Exception re) {
    logger.severe("Error while trying to store checkpoint locations into database: " +
      " Rollback failed", re);
    throw new NonstandardException("Error while trying to store checkpoint locations " +
           "into database: Rollback failed", re);
  }
 
  throw new NonstandardException("Error while trying to store checkpoint locations " +
               "into database: Rollback successful", e);
      }
    }

    // delete old checkpoints
View Full Code Here

            int status)
    throws gov.cca.CCAException {
    logger.finest("called for component: " + componentName);

    if (!componentMap.containsKey(componentName))
      throw new NonstandardException("Unknown component: " + componentName);

    synchronized(this) {
      // increment the number of outstanding components frozen
      outstandingFrozenComps++;
View Full Code Here

TOP

Related Classes of xcat.exceptions.NonstandardException

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.