Search in sources :

Example 1 with DataObjectInStore

use of com.cloud.engine.subsystem.api.storage.DataObjectInStore in project cosmic by MissionCriticalCloud.

the class TemplateObject method getInstallPath.

@Override
public String getInstallPath() {
    if (installPath != null) {
        return installPath;
    }
    if (dataStore == null) {
        return null;
    }
    // managed primary data stores should not have an install path
    if (dataStore instanceof PrimaryDataStore) {
        final PrimaryDataStore primaryDataStore = (PrimaryDataStore) dataStore;
        final Map<String, String> details = primaryDataStore.getDetails();
        final boolean managed = details != null && Boolean.parseBoolean(details.get(PrimaryDataStore.MANAGED));
        if (managed) {
            return null;
        }
    }
    final DataObjectInStore obj = objectInStoreMgr.findObject(this, dataStore);
    return obj.getInstallPath();
}
Also used : DataObjectInStore(com.cloud.engine.subsystem.api.storage.DataObjectInStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore)

Example 2 with DataObjectInStore

use of com.cloud.engine.subsystem.api.storage.DataObjectInStore in project cosmic by MissionCriticalCloud.

the class StorageCacheManagerImpl method createCacheObject.

@Override
public DataObject createCacheObject(final DataObject data, final DataStore store) {
    DataObject objOnCacheStore = null;
    final Object lock;
    final DataObjectType type = data.getType();
    final String typeName;
    final long storeId = store.getId();
    final long dataId = data.getId();
    /*
         * Make sure any thread knows own lock type.
         */
    if (type == DataObjectType.TEMPLATE) {
        lock = templateLock;
        typeName = "template";
    } else if (type == DataObjectType.VOLUME) {
        lock = volumeLock;
        typeName = "volume";
    } else if (type == DataObjectType.SNAPSHOT) {
        lock = snapshotLock;
        typeName = "snapshot";
    } else {
        final String msg = "unsupported DataObject comes, then can't acquire correct lock object";
        throw new CloudRuntimeException(msg);
    }
    s_logger.debug("check " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")");
    DataObject existingDataObj = null;
    synchronized (lock) {
        DataObjectInStore obj = objectInStoreMgr.findObject(data, store);
        if (obj != null) {
            State st = obj.getState();
            final long miliSeconds = 10000;
            final long timeoutSeconds = 3600;
            final long timeoutMiliSeconds = timeoutSeconds * 1000;
            Date now = new Date();
            final long expiredEpoch = now.getTime() + timeoutMiliSeconds;
            final Date expiredDate = new Date(expiredEpoch);
            /*
                 * Waiting for completion of cache copy.
                 */
            while (st == ObjectInDataStoreStateMachine.State.Allocated || st == ObjectInDataStoreStateMachine.State.Creating || st == ObjectInDataStoreStateMachine.State.Copying) {
                /*
                     * Threads must release lock within waiting for cache copy and
                     * must be waken up at completion.
                     */
                s_logger.debug("waiting cache copy completion type: " + typeName + ", id: " + obj.getObjectId() + ", lock: " + lock.hashCode());
                try {
                    lock.wait(miliSeconds);
                } catch (final InterruptedException e) {
                    s_logger.debug("[ignored] interupted while waiting for cache copy completion.");
                }
                s_logger.debug("waken up");
                now = new Date();
                if (now.after(expiredDate)) {
                    final String msg = "Waiting time exceeds timeout limit(" + timeoutSeconds + " s)";
                    throw new CloudRuntimeException(msg);
                }
                obj = objectInStoreMgr.findObject(data, store);
                st = obj.getState();
            }
            if (st == ObjectInDataStoreStateMachine.State.Ready) {
                s_logger.debug("there is already one in the cache store");
                final DataObject dataObj = objectInStoreMgr.get(data, store);
                dataObj.incRefCount();
                existingDataObj = dataObj;
            }
        }
        if (existingDataObj == null) {
            s_logger.debug("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")");
            objOnCacheStore = store.create(data);
        }
        lock.notifyAll();
    }
    if (existingDataObj != null) {
        return existingDataObj;
    }
    if (objOnCacheStore == null) {
        s_logger.error("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ") failed");
        return null;
    }
    final AsyncCallFuture<CopyCommandResult> future = new AsyncCallFuture<>();
    CopyCommandResult result = null;
    try {
        objOnCacheStore.processEvent(Event.CreateOnlyRequested);
        dataMotionSvr.copyAsync(data, objOnCacheStore, future);
        result = future.get();
        if (result.isFailed()) {
            objOnCacheStore.processEvent(Event.OperationFailed);
        } else {
            objOnCacheStore.processEvent(Event.OperationSuccessed, result.getAnswer());
            objOnCacheStore.incRefCount();
            return objOnCacheStore;
        }
    } catch (final InterruptedException e) {
        s_logger.debug("create cache storage failed: " + e.toString());
        throw new CloudRuntimeException(e);
    } catch (final ExecutionException e) {
        s_logger.debug("create cache storage failed: " + e.toString());
        throw new CloudRuntimeException(e);
    } finally {
        if (result == null) {
            objOnCacheStore.processEvent(Event.OperationFailed);
        }
        synchronized (lock) {
            /*
                 * Wake up all threads waiting for cache copy.
                 */
            s_logger.debug("wake up all waiting threads(lock: " + lock.hashCode() + ")");
            lock.notifyAll();
        }
    }
    return null;
}
Also used : DataObjectInStore(com.cloud.engine.subsystem.api.storage.DataObjectInStore) Date(java.util.Date) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) State(com.cloud.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) ExecutionException(java.util.concurrent.ExecutionException) DataObjectType(com.cloud.agent.api.to.DataObjectType) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Example 3 with DataObjectInStore

use of com.cloud.engine.subsystem.api.storage.DataObjectInStore in project cosmic by MissionCriticalCloud.

the class ObjectInDataStoreManagerImpl method update.

@Override
public boolean update(final DataObject data, final Event event) throws NoTransitionException, ConcurrentOperationException {
    final DataObjectInStore obj = this.findObject(data, data.getDataStore());
    if (obj == null) {
        throw new CloudRuntimeException("can't find mapping in ObjectInDataStore table for: " + data);
    }
    boolean result = true;
    if (data.getDataStore().getRole() == DataStoreRole.Image || data.getDataStore().getRole() == DataStoreRole.ImageCache) {
        switch(data.getType()) {
            case TEMPLATE:
                result = this.stateMachines.transitTo(obj, event, null, templateDataStoreDao);
                break;
            case SNAPSHOT:
                result = this.stateMachines.transitTo(obj, event, null, snapshotDataStoreDao);
                break;
            case VOLUME:
                result = this.stateMachines.transitTo(obj, event, null, volumeDataStoreDao);
                break;
        }
    } else if (data.getType() == DataObjectType.TEMPLATE && data.getDataStore().getRole() == DataStoreRole.Primary) {
        result = this.stateMachines.transitTo(obj, event, null, templatePoolDao);
    } else if (data.getType() == DataObjectType.SNAPSHOT && data.getDataStore().getRole() == DataStoreRole.Primary) {
        result = this.stateMachines.transitTo(obj, event, null, snapshotDataStoreDao);
    } else {
        throw new CloudRuntimeException("Invalid data or store type: " + data.getType() + " " + data.getDataStore().getRole());
    }
    if (!result) {
        throw new ConcurrentOperationException("Multiple threads are trying to update data object state, racing condition");
    }
    return true;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataObjectInStore(com.cloud.engine.subsystem.api.storage.DataObjectInStore) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Aggregations

DataObjectInStore (com.cloud.engine.subsystem.api.storage.DataObjectInStore)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 DataObjectType (com.cloud.agent.api.to.DataObjectType)1 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)1 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)1 State (com.cloud.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State)1 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)1 Date (java.util.Date)1 ExecutionException (java.util.concurrent.ExecutionException)1