use of org.commonjava.indy.model.galley.KeyedLocation in project indy by Commonjava.
the class DefaultDownloadManager method store.
/*
* (non-Javadoc)
* @see org.commonjava.indy.core.rest.util.FileManager#upload(org.commonjava.indy.core.model.DeployPoint,
* java.lang.String, java.io.InputStream)
*/
@Override
public Transfer store(final ArtifactStore store, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
if (store.getKey().getType() == StoreType.group) {
//FIXME: Why is this null? Investigate.
return null;
}
if (store.getKey().getType() != StoreType.hosted) {
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot deploy to non-deploy point artifact store: {}.", store.getKey());
}
if (storeManager.isReadonly(store)) {
throw new IndyWorkflowException(ApplicationStatus.METHOD_NOT_ALLOWED.code(), "The store {} is readonly. If you want to store any content to this store, please modify it to non-readonly", store.getKey());
}
if (store instanceof HostedRepository) {
final HostedRepository deploy = (HostedRepository) store;
// final ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
final ContentQuality quality = getQuality(path);
if (quality != null && quality == ContentQuality.SNAPSHOT) {
if (!deploy.isAllowSnapshots()) {
logger.error("Cannot store snapshot in non-snapshot deploy point: {}", deploy.getName());
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot store snapshot in non-snapshot deploy point: {}", deploy.getName());
}
} else if (!deploy.isAllowReleases()) {
logger.error("Cannot store release in snapshot-only deploy point: {}", deploy.getName());
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot store release in snapshot-only deploy point: {}", deploy.getName());
}
}
try {
return transfers.store(new ConcreteResource(LocationUtils.toLocation(store), path), stream, eventMetadata);
} catch (final BadGatewayException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Bad gateway: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
} catch (final TransferTimeoutException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Timeout: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
} catch (final TransferLocationException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
logger.warn("Location Error: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
} catch (TransferException e) {
logger.error(String.format("Failed to store: %s in: %s. Reason: %s", path, store.getKey(), e.getMessage()), e);
throw new IndyWorkflowException("Failed to store: %s in: %s. Reason: %s", e, path, store.getKey(), e.getMessage());
}
}
use of org.commonjava.indy.model.galley.KeyedLocation in project indy by Commonjava.
the class DefaultContentManager method store.
@Override
public Transfer store(final ArtifactStore store, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
if (group == store.getKey().getType()) {
try {
final List<ArtifactStore> allMembers = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
final Transfer txfr = store(allMembers, store.getKey(), path, stream, op, eventMetadata);
logger.info("Stored: {} for group: {} in: {}", path, store.getKey(), txfr);
return txfr;
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
}
}
logger.info("Storing: {} for: {} with event metadata: {}", path, store.getKey(), eventMetadata);
final Transfer txfr = downloadManager.store(store, path, stream, op, eventMetadata);
if (txfr != null) {
final KeyedLocation kl = (KeyedLocation) txfr.getLocation();
ArtifactStore transferStore;
try {
transferStore = storeManager.getArtifactStore(kl.getKey());
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup store: %s. Reason: %s", e, kl.getKey(), e.getMessage());
}
for (final ContentGenerator generator : contentGenerators) {
generator.handleContentStorage(transferStore, path, txfr, eventMetadata);
}
if (!store.equals(transferStore)) {
for (final ContentGenerator generator : contentGenerators) {
generator.handleContentStorage(transferStore, path, txfr, eventMetadata);
}
}
}
return txfr;
}
use of org.commonjava.indy.model.galley.KeyedLocation in project indy by Commonjava.
the class DefaultContentManager method store.
// @Override
// public Transfer store( final List<? extends ArtifactStore> stores, final String path, final InputStream stream,
// final TransferOperation op )
// throws IndyWorkflowException
// {
// return store( stores, path, stream, op, new EventMetadata() );
// }
@Override
public Transfer store(final List<? extends ArtifactStore> stores, final StoreKey topKey, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
logger.info("Storing: {} in: {} with event metadata: {}", path, stores, eventMetadata);
final Transfer txfr = downloadManager.store(stores, path, stream, op, eventMetadata);
if (txfr != null) {
final KeyedLocation kl = (KeyedLocation) txfr.getLocation();
ArtifactStore transferStore;
try {
transferStore = storeManager.getArtifactStore(kl.getKey());
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup store: %s. Reason: %s", e, kl.getKey(), e.getMessage());
}
for (final ContentGenerator generator : contentGenerators) {
logger.info("{} Handling content storage of: {} in: {}", generator, path, transferStore.getKey());
generator.handleContentStorage(transferStore, path, txfr, eventMetadata);
}
}
return txfr;
}
use of org.commonjava.indy.model.galley.KeyedLocation in project indy by Commonjava.
the class IndyPathGenerator method getFilePath.
@Override
public String getFilePath(final ConcreteResource resource) {
final KeyedLocation kl = (KeyedLocation) resource.getLocation();
final StoreKey key = kl.getKey();
final String name = key.getPackageType() + "/" + key.getType().name() + "-" + key.getName();
String path = resource.getPath();
if (hashed == kl.getAttribute(LocationUtils.PATH_STYLE, PathStyle.class)) {
File f = new File(path);
String dir = f.getParent();
if (dir == null) {
dir = "";
}
if (dir.length() > 1 && dir.startsWith("/")) {
dir = dir.substring(1, dir.length());
}
String digest = DigestUtils.sha256Hex(dir);
Logger logger = LoggerFactory.getLogger(getClass());
logger.trace("Using SHA-256 digest: '{}' for dir: '{}' of path: '{}'", digest, dir, path);
// Format examples:
// - aa/bb/aabbccddeeff001122/simple-1.0.pom
// - aa/bb/aabbccddeeff001122/gulp-size
// - 00/11/001122334455667788/gulp-size-1.3.0.tgz
path = String.format("%s/%s/%s/%s", digest.substring(0, 2), digest.substring(2, 4), digest, f.getName());
}
return PathUtils.join(name, path);
}
use of org.commonjava.indy.model.galley.KeyedLocation in project indy by Commonjava.
the class LocationUtils method toLocation.
public static KeyedLocation toLocation(final ArtifactStore store) {
if (store == null) {
return null;
}
final StoreType type = store.getKey().getType();
KeyedLocation location = null;
switch(type) {
case group:
{
location = new GroupLocation(store.getName());
break;
}
case hosted:
{
location = new CacheOnlyLocation((HostedRepository) store);
break;
}
case remote:
default:
{
final RemoteRepository repository = (RemoteRepository) store;
location = new RepositoryLocation(repository);
AttributePasswordManager.bind(location, PasswordEntry.KEY_PASSWORD, repository.getKeyPassword());
AttributePasswordManager.bind(location, PasswordEntry.PROXY_PASSWORD, repository.getProxyPassword());
AttributePasswordManager.bind(location, PasswordEntry.USER_PASSWORD, repository.getPassword());
// FIXME: Make this configurable on the RemoteRepository!
location.setAttribute(Location.MAX_CONNECTIONS, 30);
}
}
if (location != null) {
location.setAttribute(PATH_STYLE, store.getPathStyle());
Map<String, String> metadata = store.getMetadata();
if (metadata != null) {
Location loc = location;
metadata.forEach((k, v) -> {
if (!loc.getAttributes().containsKey(k)) {
loc.setAttribute(k, v);
}
});
}
}
return location;
}
Aggregations