use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class FoloPomDownloadListener method onFileUpload.
public void onFileUpload(@Observes final FileStorageEvent event) {
// check for a TransferOperation of DOWNLOAD
final TransferOperation op = event.getType();
if (op != TransferOperation.DOWNLOAD) {
logger.trace("Not a download transfer operation. No pom existence check performed.");
return;
}
// check if it is a path that doesn't end in with ".pom"
final Transfer transfer = event.getTransfer();
if (transfer == null) {
logger.trace("No transfer. No pom existence check performed.");
return;
}
String txfrPath = transfer.getPath();
if (txfrPath.endsWith(".pom")) {
logger.trace("This is a pom download.");
return;
}
// use ArtifactPathInfo to parse into a GAV, just to verify that it's looking at an artifact download
ArtifactPathInfo artPathInfo = ArtifactPathInfo.parse(txfrPath);
if (artPathInfo == null) {
logger.trace("Not an artifact download ({}). No pom existence check performed.", txfrPath);
return;
}
// verify that the associated .pom file exists
String pomFilename = String.format("%s-%s.pom", artPathInfo.getArtifactId(), artPathInfo.getVersion());
ConcreteResource pomResource = transfer.getResource().getParent().getChild(pomFilename);
if (cacheProvider.exists(pomResource)) {
logger.trace("Pom {} already exists.", cacheProvider.getFilePath(pomResource));
return;
}
// trigger pom download by requesting it from the same repository as the original artifact
StoreKey storeKey = StoreKey.fromString(transfer.getLocation().getName());
ArtifactStore store;
try {
store = storeManager.getArtifactStore(storeKey);
} catch (final IndyDataException ex) {
logger.error("Error retrieving artifactStore with key " + storeKey, ex);
return;
}
try {
logger.debug("Downloading POM as automatic response to associated artifact download: {}/{}", storeKey, pomResource.getPath());
contentManager.retrieve(store, pomResource.getPath(), event.getEventMetadata());
} catch (final IndyWorkflowException ex) {
logger.error("Error while retrieving pom artifact " + pomResource.getPath() + " from store " + store, ex);
return;
}
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class SettingsSubStore method getSettingsTemplate.
private synchronized SettingsTemplate getSettingsTemplate(final URIMatcher matcher) throws WebdavException {
final StoreKey key = matcher.getStoreKey();
ArtifactStore store;
try {
store = indy.getArtifactStore(key);
} catch (final IndyDataException e) {
logger.error(String.format("Failed to retrieve artifact store: %s. Reason: %s", key, e.getMessage()), e);
throw new WebdavException("Failed to retrieve length for: " + matcher.getURI());
}
if (store == null) {
throw new WebdavException("Cannot retrieve ArtifactStore: " + key);
}
StorageAdvice advice;
try {
advice = advisor.getStorageAdvice(store);
} catch (final DotMavenException e) {
logger.error(String.format("Failed to retrieve storage advice for: %s. Reason: %s", key, e.getMessage()), e);
throw new WebdavException("Failed to retrieve length for: " + matcher.getURI());
}
return new SettingsTemplate(key, advice, requestInfo, templatingEngine);
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class StorageAdvisor method getStorageAdvice.
public StorageAdvice getStorageAdvice(final ArtifactStore store) throws DotMavenException {
boolean deployable = false;
boolean releases = true;
boolean snapshots = false;
HostedRepository hostedStore = null;
final StoreType type = store.getKey().getType();
all: switch(type) {
case group:
{
List<ArtifactStore> constituents;
try {
constituents = dataManager.query().enabledState(true).getOrderedConcreteStoresInGroup(MAVEN_PKG_KEY, store.getName());
} catch (final IndyDataException e) {
throw new DotMavenException("Failed to retrieve constituent ArtifactStores for group: %s. Reason: %s", e, store.getName(), e.getMessage());
}
for (final ArtifactStore as : constituents) {
if (as.getKey().getType() == hosted) {
deployable = true;
hostedStore = (HostedRepository) as;
snapshots = hostedStore.isAllowSnapshots();
releases = hostedStore.isAllowReleases();
break all;
}
}
break;
}
case hosted:
{
deployable = true;
hostedStore = (HostedRepository) store;
snapshots = hostedStore.isAllowSnapshots();
releases = hostedStore.isAllowReleases();
break;
}
default:
}
return new StorageAdvice(store, hostedStore, deployable, releases, snapshots);
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class RepoProxyContentLimiter method clearContent.
private void clearContent(String skp) {
String[] parts = skp.split("#");
StoreKey storeKey = StoreKey.fromString(parts[0]);
if (remote == storeKey.getType()) {
ArtifactStore store;
try {
store = storeDataManager.getArtifactStore(storeKey);
contentManager.delete(store, parts[1]);
} catch (IndyDataException e) {
logger.warn("Failed to lookup store: {} from event: {}", storeKey, skp);
} catch (IndyWorkflowException e) {
logger.warn("Failed to delete: {} from: {}, from event: {}", parts[1], storeKey, skp);
}
}
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class ScheduleDBManager method rescheduleDisableTimeout.
public void rescheduleDisableTimeout(final StoreKey key) throws IndySchedulerException {
if (!schedulerConfig.isEnabled()) {
logger.debug("Scheduler disabled.");
return;
}
ArtifactStore store = null;
try {
store = dataManager.getArtifactStore(key);
} catch (final IndyDataException e) {
logger.error(String.format("Failed to retrieve store for: %s. Reason: %s", key, e.getMessage()), e);
}
if (store == null) {
return;
}
int timeout = store.getDisableTimeout();
if (timeout == TIMEOUT_USE_DEFAULT) {
// case TIMEOUT_USE_DEFAULT: will use default timeout configuration
timeout = config.getStoreDisableTimeoutSeconds();
}
if (timeout > TIMEOUT_USE_DEFAULT && store.isDisabled()) {
final StoreKey sk = store.getKey();
logger.debug("Set/Reschedule disable timeout for store:{}", sk);
scheduleForStore(sk, DISABLE_TIMEOUT, sk.toString() + "#" + DISABLE_TIMEOUT, sk, timeout);
}
}
Aggregations