Search in sources :

Example 86 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class TimeoutEventListener method onExpirationEvent.

//    @Inject
//    @ExecutorConfig( daemon = true, priority = 7, named = "indy-events" )
//    private Executor executor;
public void onExpirationEvent(@Observes final SchedulerEvent event) {
    if (!(event instanceof SchedulerTriggerEvent) || !event.getJobType().equals(ScheduleManager.CONTENT_JOB_TYPE)) {
        return;
    }
    ContentExpiration expiration;
    try {
        expiration = objectMapper.readValue(event.getPayload(), ContentExpiration.class);
    } catch (final IOException e) {
        logger.error("Failed to read ContentExpiration from event payload.", e);
        return;
    }
    final StoreKey key = expiration.getKey();
    final String path = expiration.getPath();
    try {
        ArtifactStore store = storeManager.getArtifactStore(key);
        boolean deleted = contentManager.delete(store, path);
        if (!deleted) {
            logger.error("Failed to delete Transfer for: {} in: {} (for content timeout).", path, key);
        } else {
            deleteExpiration(key, path);
        }
    } catch (IndyWorkflowException e) {
        logger.error(String.format("Failed to retrieve Transfer for: %s in: %s (for content timeout). Reason: %s", path, key, e), e);
    } catch (IndyDataException e) {
        scheduleManager.deleteJob(scheduleManager.groupName(key, ScheduleManager.CONTENT_JOB_TYPE), path);
        logger.error(String.format("Failed to retrieve ArtifactStore for: %s (for content timeout). Reason: %s", key, e), e);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) IOException(java.io.IOException) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 87 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class ReplicationController method getRemoteStores.

// FIXME: Find a better solution to the passed-in generic deserialization problem...erasure is a mother...
private List<? extends ArtifactStore> getRemoteStores(final ReplicationDTO dto) throws IndyWorkflowException {
    final String apiUrl = dto.getApiUrl();
    String remotesUrl = null;
    String groupsUrl = null;
    String hostedUrl = null;
    try {
        remotesUrl = buildUrl(apiUrl, "/admin/remotes");
        groupsUrl = buildUrl(apiUrl, "/admin/groups");
        hostedUrl = buildUrl(apiUrl, "/admin/hosted");
    } catch (final MalformedURLException e) {
        throw new IndyWorkflowException("Failed to construct store definition-retrieval URL from api-base: {}. Reason: {}", e, apiUrl, e.getMessage());
    }
    //        logger.info( "\n\n\n\n\n[AutoProx] Checking URL: {} from:", new Throwable(), url );
    final List<ArtifactStore> result = new ArrayList<ArtifactStore>();
    addStoresFrom(result, remotesUrl, dto, RemoteRepository.class);
    addStoresFrom(result, groupsUrl, dto, Group.class);
    addStoresFrom(result, hostedUrl, dto, HostedRepository.class);
    return result;
}
Also used : MalformedURLException(java.net.MalformedURLException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArrayList(java.util.ArrayList)

Example 88 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class ReplicationController method replicate.

public Set<StoreKey> replicate(final ReplicationDTO dto, final String user) throws IndyWorkflowException {
    final ReplicationRepositoryCreator creator = createRepoCreator();
    if (creator == null) {
        throw new IndyWorkflowException(500, "Cannot replicate; ReplicationRepositoryCreator could not be instantiated.");
    }
    try {
        dto.validate();
    } catch (final IndyException e) {
        throw new IndyWorkflowException("Invalid replication request DTO: %s", e, e.getMessage());
    }
    List<? extends ArtifactStore> remoteStores = null;
    List<EndpointView> remoteEndpoints = null;
    final boolean overwrite = dto.isOverwrite();
    final Set<StoreKey> replicated = new HashSet<StoreKey>();
    for (final ReplicationAction action : dto) {
        if (action == null) {
            continue;
        }
        logger.info("Processing replication action:\n\n  {}\n\nin DTO: {}\n\n", action, dto);
        final String include = action.getInclude();
        final String exclude = action.getExclude();
        try {
            if (action.getType() == ActionType.PROXY) {
                if (remoteEndpoints == null) {
                    remoteEndpoints = getEndpoints(dto);
                }
                for (final EndpointView view : remoteEndpoints) {
                    final String key = "remote-" + view.getType() + "_" + view.getName();
                    if ((include == null || key.matches(include)) && (exclude == null || !key.matches(exclude))) {
                        final StoreKey sk = new StoreKey(StoreType.remote, key);
                        if (overwrite || !data.hasArtifactStore(sk)) {
                            RemoteRepository repo = creator.createRemoteRepository(key, view);
                            repo.setMetadata(ArtifactStore.METADATA_ORIGIN, REPLICATION_ORIGIN);
                            setProxyAttributes(repo, action);
                            data.storeArtifactStore(repo, new ChangeSummary(user, "REPLICATION: Proxying remote indy repository: " + view.getResourceUri()), true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, REPLICATION_ORIGIN));
                            replicated.add(repo.getKey());
                        }
                    }
                }
            } else if (action.getType() == ActionType.MIRROR) {
                if (remoteStores == null) {
                    remoteStores = getRemoteStores(dto);
                }
                for (final ArtifactStore store : remoteStores) {
                    final String key = store.getKey().toString();
                    if ((include == null || key.matches(include)) && (exclude == null || !key.matches(exclude))) {
                        if (overwrite || !data.hasArtifactStore(store.getKey())) {
                            if (store instanceof RemoteRepository) {
                                setProxyAttributes(((RemoteRepository) store), action);
                            }
                            data.storeArtifactStore(store, new ChangeSummary(user, "REPLICATION: Mirroring remote indy store: " + store.getKey()), true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, REPLICATION_ORIGIN));
                            replicated.add(store.getKey());
                        }
                    }
                }
            }
        } catch (final IndyDataException e) {
            logger.error(e.getMessage(), e);
            throw new IndyWorkflowException(e.getMessage(), e);
        }
    }
    return replicated;
}
Also used : EndpointView(org.commonjava.indy.model.core.dto.EndpointView) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) IndyException(org.commonjava.indy.IndyException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ReplicationAction(org.commonjava.indy.model.core.dto.ReplicationAction) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) HashSet(java.util.HashSet)

Example 89 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class SchedulerController method getDisabledStores.

public ExpirationSet getDisabledStores() throws IndyWorkflowException {
    try {
        // This key matcher will compare with the cache key group to see if the group ends with the "Disable-Timeout"(jobtype)
        ExpirationSet expirations = scheduleManager.findMatchingExpirations(cacheHandle -> cacheHandle.execute(Cache::keySet).stream().filter(key -> key.getType().equals(StoreEnablementManager.DISABLE_TIMEOUT)).collect(Collectors.toSet()));
        // TODO: This seems REALLY inefficient...
        storeDataManager.getAllArtifactStores().forEach((store) -> {
            if (store.isDisabled()) {
                expirations.getItems().add(indefiniteDisable(store));
            }
        });
        return expirations;
    } catch (IndyDataException e) {
        throw new IndyWorkflowException("Failed to load stores to check for indefinite disable. Reason: %s", e, e.getMessage());
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ExpirationSet(org.commonjava.indy.core.expire.ExpirationSet) Cache(org.infinispan.Cache)

Example 90 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class StatsController method getActiveAddOnsJavascript.

public String getActiveAddOnsJavascript() throws IndyWorkflowException {
    try {
        final String json = serializer.writeValueAsString(getActiveAddOns());
        final Map<String, Object> params = new HashMap<>();
        final Map<String, String> jsMap = new HashMap<>();
        if (addons != null) {
            final ClassLoader cl = Thread.currentThread().getContextClassLoader();
            for (final IndyAddOn addon : addons) {
                final String jsRef = addon.getId().getInitJavascriptHref();
                if (jsRef == null) {
                    logger.debug("Add-On has no init javascript: {}", addon);
                    continue;
                }
                try (InputStream in = cl.getResourceAsStream(jsRef)) {
                    if (in == null) {
                        logger.error("Add-On failed to load: {}. Initialization javascript NOT FOUND in classpath: {}", addon, jsRef);
                        continue;
                    }
                    jsMap.put(jsRef, IOUtils.toString(in));
                } catch (final IOException e) {
                    logger.error("Add-On failed to load: {}. Cannot load initialization javascript from classpath: {}", addon, jsRef);
                }
            }
        }
        params.put(ADDONS_KEY, json);
        params.put(ADDONS_LOGIC, jsMap);
        return templates.render(ACTIVE_ADDONS_JS, params);
    } catch (final IndyGroovyException e) {
        throw new IndyWorkflowException("Failed to render javascript wrapper for active addons. Reason: %s", e, e.getMessage());
    } catch (final JsonProcessingException e) {
        throw new IndyWorkflowException("Failed to render javascript wrapper for active addons. Reason: %s", e, e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) IndyAddOn(org.commonjava.indy.spi.IndyAddOn) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IndyGroovyException(org.commonjava.indy.subsys.template.IndyGroovyException)

Aggregations

IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)109 Response (javax.ws.rs.core.Response)40 Transfer (org.commonjava.maven.galley.model.Transfer)39 IOException (java.io.IOException)36 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)36 StoreKey (org.commonjava.indy.model.core.StoreKey)36 ApiOperation (io.swagger.annotations.ApiOperation)35 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)34 ApiResponse (io.swagger.annotations.ApiResponse)33 Path (javax.ws.rs.Path)32 StoreType (org.commonjava.indy.model.core.StoreType)26 IndyDataException (org.commonjava.indy.data.IndyDataException)25 GET (javax.ws.rs.GET)24 Logger (org.slf4j.Logger)22 ApiResponses (io.swagger.annotations.ApiResponses)21 ArrayList (java.util.ArrayList)19 Produces (javax.ws.rs.Produces)18 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)18 InputStream (java.io.InputStream)15 List (java.util.List)13