Search in sources :

Example 31 with HyracksException

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;
}
Also used : DefaultDeallocatableRegistry(org.apache.hyracks.control.nc.resources.DefaultDeallocatableRegistry) ResultStateSweeper(org.apache.hyracks.control.common.dataset.ResultStateSweeper) Executor(java.util.concurrent.Executor) IDatasetStateRecord(org.apache.hyracks.api.dataset.IDatasetStateRecord) Set(java.util.Set) IFrameWriter(org.apache.hyracks.api.comm.IFrameWriter) IDatasetPartitionManager(org.apache.hyracks.api.dataset.IDatasetPartitionManager) WorkspaceFileFactory(org.apache.hyracks.control.nc.io.WorkspaceFileFactory) IWorkspaceFileFactory(org.apache.hyracks.api.io.IWorkspaceFileFactory) Logger(java.util.logging.Logger) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) LinkedHashMap(java.util.LinkedHashMap) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) NodeControllerService(org.apache.hyracks.control.nc.NodeControllerService) JobId(org.apache.hyracks.api.job.JobId) Map(java.util.Map) ResultSetId(org.apache.hyracks.api.dataset.ResultSetId) JobId(org.apache.hyracks.api.job.JobId)

Example 32 with HyracksException

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);
    }
}
Also used : HyracksException(org.apache.hyracks.api.exceptions.HyracksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 33 with HyracksException

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);
    }
}
Also used : HyracksException(org.apache.hyracks.api.exceptions.HyracksException) File(java.io.File) IOException(java.io.IOException) HyracksException(org.apache.hyracks.api.exceptions.HyracksException)

Example 34 with HyracksException

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);
    }
}
Also used : HyracksException(org.apache.hyracks.api.exceptions.HyracksException) URL(java.net.URL) HyracksException(org.apache.hyracks.api.exceptions.HyracksException)

Example 35 with HyracksException

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);
}
Also used : InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) IOException(java.io.IOException) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) URL(java.net.URL) HttpClient(org.apache.http.client.HttpClient) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

HyracksException (org.apache.hyracks.api.exceptions.HyracksException)48 IOException (java.io.IOException)10 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)8 JobId (org.apache.hyracks.api.job.JobId)8 HashMap (java.util.HashMap)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 IJobCapacityController (org.apache.hyracks.api.job.resource.IJobCapacityController)5 INodeManager (org.apache.hyracks.control.cc.cluster.INodeManager)5 JobRun (org.apache.hyracks.control.cc.job.JobRun)5 URL (java.net.URL)4 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)4 NodeControllerState (org.apache.hyracks.control.cc.NodeControllerState)4 File (java.io.File)3 HashSet (java.util.HashSet)3 NodeControllerInfo (org.apache.hyracks.api.client.NodeControllerInfo)3 JobSpecification (org.apache.hyracks.api.job.JobSpecification)3 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2