Search in sources :

Example 6 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class MemoryStoreDataManager method deleteArtifactStore.

@Override
public void deleteArtifactStore(final StoreKey key, final ChangeSummary summary, final EventMetadata eventMetadata) throws IndyDataException {
    Logger logger = LoggerFactory.getLogger(getClass());
    ReentrantLock opLock = getOpLock(key);
    try {
        logger.info("DELETE operation starting for store: {}", key);
        opLock.lock();
        final ArtifactStore store = stores.get(key);
        if (store == null) {
            logger.warn("No store found for: {}", key);
            return;
        }
        if (isReadonly(store)) {
            throw new IndyDataException(ApplicationStatus.METHOD_NOT_ALLOWED.code(), "The store {} is readonly. If you want to delete this store, please modify it to non-readonly", store.getKey());
        }
        preDelete(store, summary, true, eventMetadata);
        ArtifactStore removed = stores.remove(key);
        logger.info("REMOVED store: {}", removed);
        postDelete(store, summary, true, eventMetadata);
    } finally {
        opLock.unlock();
        logger.trace("Delete operation complete: {}", key);
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Logger(org.slf4j.Logger)

Example 7 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class DataFileStoreDataManager method delete.

private void delete(final ArtifactStore store, final ChangeSummary summary) throws IndyDataException {
    logger.trace("Attempting to delete data file for store: {}", store.getKey());
    final DataFile f = manager.getDataFile(INDY_STORE, store.getPackageType(), store.getType().singularEndpointName(), store.getName() + ".json");
    try {
        logger.trace("Deleting file: {}", f);
        f.delete(summary);
    } catch (final IOException e) {
        throw new IndyDataException("Cannot delete store definition: {} in file: {}. Reason: {}", e, store.getKey(), f, e.getMessage());
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IndyDataException(org.commonjava.indy.data.IndyDataException) IOException(java.io.IOException)

Example 8 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class DataFileStoreDataManager method store.

private void store(final boolean skipIfExists, final ChangeSummary summary, final ArtifactStore... stores) throws IndyDataException {
    for (final ArtifactStore store : stores) {
        final DataFile f = manager.getDataFile(INDY_STORE, store.getPackageType(), store.getType().singularEndpointName(), store.getName() + ".json");
        if (skipIfExists && f.exists()) {
            continue;
        }
        final DataFile d = f.getParent();
        if (!d.mkdirs()) {
            throw new IndyDataException("Cannot create storage directory: {} for definition: {}", d, store);
        }
        try {
            final String json = serializer.writeValueAsString(store);
            f.writeString(json, "UTF-8", summary);
            logger.debug("Persisted {} to disk at: {}\n{}", store, f, json);
        } catch (final IOException e) {
            throw new IndyDataException("Cannot write definition: {} to: {}. Reason: {}", e, store, f, e.getMessage());
        }
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IOException(java.io.IOException)

Example 9 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class StoreEnablementManager method onStoreError.

//    public void onStoreUpdate( @Observes ArtifactStorePostUpdateEvent event )
//    {
//        for ( ArtifactStore store : event )
//        {
//            if ( store.isDisabled() )
//            {
//                String toStr = store.getMetadata( DISABLE_TIMEOUT );
//                if ( isNotEmpty( toStr ) )
//                {
//                    int timeout = Integer.parseInt( toStr );
//                    try
//                    {
//                        setReEnablementTimeout( store.getKey(), timeout );
//                    }
//                    catch ( IndySchedulerException e )
//                    {
//                        Logger logger = LoggerFactory.getLogger( getClass() );
//                        logger.error( String.format( "Failed to schedule re-enablement of %s.", store.getKey() ), e );
//                    }
//                }
//            }
////            else
////            {
////                try
////                {
////                    cancelReEnablementTimeout( store.getKey() );
////                }
////                catch ( IndySchedulerException e )
////                {
////                    Logger logger = LoggerFactory.getLogger( getClass() );
////                    logger.error( String.format( "Failed to delete re-enablement job for %s.", store.getKey() ), e );
////                }
////            }
//        }
//    }
public void onStoreError(@Observes IndyStoreErrorEvent evt) {
    Logger logger = LoggerFactory.getLogger(getClass());
    StoreKey key = evt.getStoreKey();
    Throwable error = evt.getError();
    try {
        ArtifactStore store = storeDataManager.getArtifactStore(key);
        if (store.getDisableTimeout() <= TIMEOUT_NEVER_DISABLE) {
            logger.debug("Disable-timeout set to {}, will never disable the repo", store.getDisableTimeout());
            store.setDisabled(false);
        } else {
            store.setDisabled(true);
        }
        final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, String.format("Disabling %s due to error: %s\n\nStack Trace:\n  %s", key, error, StringUtils.join(error.getStackTrace(), "\n  ")));
        storeDataManager.storeArtifactStore(store, changeSummary, false, true, new EventMetadata());
        logger.warn("{} has been disabled due to store-level error: {}\n Will re-enable in {} seconds.", key, error, config.getStoreDisableTimeoutSeconds());
        // TODO: How is it this doesn't duplicate the event handler method onStoreUpdate()...we're updating the store just above here.
        setReEnablementTimeout(key);
    } catch (IndyDataException e) {
        logger.error(String.format("Failed to disable %s on error: %s", key, error), e);
    } catch (IndySchedulerException e) {
        logger.error(String.format("Failed to schedule re-enablement of %s for retry.", key), e);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Logger(org.slf4j.Logger) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) IndySchedulerException(org.commonjava.indy.core.expire.IndySchedulerException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 10 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class StoreEnablementManager method onDisableTimeout.

public void onDisableTimeout(@Observes SchedulerEvent evt) {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Checking for store-reenable event in: {} (trigger? {} Disable-Timeout? {})", evt, evt instanceof SchedulerTriggerEvent, DISABLE_TIMEOUT.equals(evt.getJobType()));
    if ((evt instanceof SchedulerTriggerEvent) && DISABLE_TIMEOUT.equals(evt.getJobType())) {
        String keystr = evt.getPayload();
        StoreKey key = null;
        try {
            key = objectMapper.readValue(keystr, StoreKey.class);
        } catch (IOException e) {
            logger.warn("Failed to read StoreKey from JSON string: '{}' in event payload.", keystr);
        }
        logger.debug("Read key: {} from JSON string: '{}' in event payload.", key, keystr);
        if (key != null) {
            try {
                ArtifactStore store = storeDataManager.getArtifactStore(key);
                if (store.isDisabled()) {
                    store.setDisabled(false);
                    storeDataManager.storeArtifactStore(store, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Re-enabling " + key), false, true, new EventMetadata());
                    cancelReEnablementTimeout(key);
                }
            } catch (IndyDataException e) {
                logger.error(String.format("Failed to re-enable %s", key), e);
            } catch (IndySchedulerException e) {
                logger.error(String.format("Failed to delete re-enablement job for %s.", key), e);
            }
        }
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) SchedulerTriggerEvent(org.commonjava.indy.core.expire.SchedulerTriggerEvent) IOException(java.io.IOException) Logger(org.slf4j.Logger) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) IndySchedulerException(org.commonjava.indy.core.expire.IndySchedulerException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Aggregations

IndyDataException (org.commonjava.indy.data.IndyDataException)75 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)50 StoreKey (org.commonjava.indy.model.core.StoreKey)30 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)26 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)24 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)24 Transfer (org.commonjava.maven.galley.model.Transfer)19 ArrayList (java.util.ArrayList)17 Group (org.commonjava.indy.model.core.Group)17 IOException (java.io.IOException)16 Logger (org.slf4j.Logger)16 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)14 HashSet (java.util.HashSet)10 List (java.util.List)7 StoreType (org.commonjava.indy.model.core.StoreType)7 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)7 HostedRepository (org.commonjava.indy.model.core.HostedRepository)6 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)6 ContentGenerator (org.commonjava.indy.content.ContentGenerator)5 InputStream (java.io.InputStream)4