use of org.apache.hyracks.api.exceptions.HyracksException in project asterixdb by apache.
the class DatasetPartitionManager method createDatasetPartitionWriter.
@Override
public IFrameWriter createDatasetPartitionWriter(IHyracksTaskContext ctx, ResultSetId rsId, boolean orderedResult, boolean asyncMode, int partition, int nPartitions) throws HyracksException {
DatasetPartitionWriter dpw;
JobId jobId = ctx.getJobletContext().getJobId();
synchronized (this) {
dpw = new DatasetPartitionWriter(ctx, this, jobId, rsId, asyncMode, orderedResult, partition, nPartitions, datasetMemoryManager, fileFactory);
ResultSetMap rsIdMap = (ResultSetMap) partitionResultStateMap.computeIfAbsent(jobId, k -> new ResultSetMap());
ResultState[] resultStates = rsIdMap.createOrGetResultStates(rsId, nPartitions);
resultStates[partition] = dpw.getResultState();
}
LOGGER.fine("Initialized partition writer: JobId: " + jobId + ":partition: " + partition);
return dpw;
}
use of org.apache.hyracks.api.exceptions.HyracksException in project asterixdb by apache.
the class DatasetPartitionWriter method fail.
@Override
public void fail() throws HyracksDataException {
try {
failed = true;
resultState.closeAndDelete();
resultState.abort();
registerResultPartitionLocation(false);
manager.reportPartitionFailure(jobId, resultSetId, partition);
} catch (HyracksException e) {
throw new HyracksDataException(e);
}
}
use of org.apache.hyracks.api.exceptions.HyracksException in project asterixdb by apache.
the class DeploymentUtils method undeploy.
/**
* undeploy an existing deployment
*
* @param deploymentId
* the deployment id
* @param container
* @param ctx
* @throws HyracksException
*/
public static void undeploy(DeploymentId deploymentId, IJobSerializerDeserializerContainer container, ServerContext ctx) throws HyracksException {
container.removeJobSerializerDeserializer(deploymentId);
String rootDir = ctx.getBaseDir().toString();
String deploymentDir = rootDir.endsWith(File.separator) ? rootDir + DEPLOYMENT + File.separator + deploymentId : rootDir + File.separator + DEPLOYMENT + File.separator + deploymentId;
try {
File dFile = new File(deploymentDir);
if (dFile.exists()) {
FileUtils.forceDelete(dFile);
}
} catch (Exception e) {
throw new HyracksException(e);
}
}
use of org.apache.hyracks.api.exceptions.HyracksException in project asterixdb by apache.
the class ClassLoaderJobSerializerDeserializer method addClassPathURLs.
@Override
public void addClassPathURLs(List<URL> binaryURLs) throws HyracksException {
Collections.sort(binaryURLs, new Comparator<URL>() {
@Override
public int compare(URL o1, URL o2) {
return o1.getFile().compareTo(o2.getFile());
}
});
try {
if (classLoader == null) {
/** crate a new classloader */
URL[] urls = binaryURLs.toArray(new URL[binaryURLs.size()]);
classLoader = new MutableURLClassLoader(urls, this.getClass().getClassLoader());
} else {
/** add URLs to the existing classloader */
for (URL url : binaryURLs) {
classLoader.addURL(url);
}
}
} catch (Exception e) {
throw new HyracksException(e);
}
}
use of org.apache.hyracks.api.exceptions.HyracksException in project asterixdb by apache.
the class DeploymentUtils method downloadURLs.
/**
* Download remote Http URLs and return the stored local file URLs
*
* @param urls
* the remote Http URLs
* @param deploymentDir
* the deployment jar storage directory
* @param isNC
* true is NC/false is CC
* @return a list of local file URLs
* @throws HyracksException
*/
private static List<URL> downloadURLs(List<URL> urls, String deploymentDir, boolean isNC) throws HyracksException {
//retry 10 times at maximum for downloading binaries
int retryCount = 10;
int tried = 0;
Exception trace = null;
while (tried < retryCount) {
try {
tried++;
List<URL> downloadedFileURLs = new ArrayList<>();
File dir = new File(deploymentDir);
if (!dir.exists()) {
FileUtils.forceMkdir(dir);
}
for (URL url : urls) {
String urlString = url.toString();
int slashIndex = urlString.lastIndexOf('/');
String fileName = urlString.substring(slashIndex + 1).split("&")[1];
String filePath = deploymentDir + File.separator + fileName;
File targetFile = new File(filePath);
if (isNC) {
HttpClient hc = HttpClientBuilder.create().build();
HttpGet get = new HttpGet(url.toString());
HttpResponse response = hc.execute(get);
InputStream is = response.getEntity().getContent();
OutputStream os = new FileOutputStream(targetFile);
try {
IOUtils.copyLarge(is, os);
} finally {
os.close();
is.close();
}
}
downloadedFileURLs.add(targetFile.toURI().toURL());
}
return downloadedFileURLs;
} catch (Exception e) {
e.printStackTrace();
trace = e;
}
}
throw new HyracksException(trace);
}
Aggregations