Package org.apache.stanbol.enhancer.servicesapi

Examples of org.apache.stanbol.enhancer.servicesapi.ChainException


         * {@link GraphChain#parser} is not available, any exception during
         * parsing or if the parsed RDF data are not a valid execution plan
         */
        private void updateExecutionPlan() throws ChainException {
            if(resourceData == null){
                throw new ChainException("The configured resource '"+resourceName+
                    "' for the execution plan is not available via the" +
                    "DataFileProvider infrastructure");
            }
            if(parser == null){
                throw new ChainException("Unable to parse RDF data from resource '"+
                    resourceName+"' because the RDF parser service is not available!");
            }
            try {
                executionPlan = parser.parse(new ByteArrayInputStream(resourceData), format);
            }catch(Exception e){
                throw new ChainException("Unable to parse RDF from resource '"+resourceName+
                    "' using format '"+format+"'!",e);
            }
            resourceData = null; //we have the graph no need to keep the raw data
            //we need still to parse the engines and to validate the plan
            engineNames = validateExecutionPlan(executionPlan);
View Full Code Here


        //1. check the ExecutionNodes
        while(executionNodeIt.hasNext()){
            NonLiteral node = executionNodeIt.next().getSubject();
            Iterator<String> engines = EnhancementEngineHelper.getStrings(executionPlan, node,ENGINE);
            if(!engines.hasNext()){
                throw new ChainException("Execution Node "+node+" does not define " +
                        "the required property "+ENGINE+"!");
            }
            String engine = engines.next();
            if(engines.hasNext()){
                throw new ChainException("Execution Node "+node+" does not define " +
                        "multiple values for the property "+ENGINE+"!");
            }
            if(engine.isEmpty()){
                throw new ChainException("Execution Node "+node+" does not define " +
                        "an empty String as engine name (property "+ENGINE+")!");
            }
            engineNames.add(engine);
            Collection<NonLiteral> dependsOn = new HashSet<NonLiteral>();
            for(Iterator<Triple> t = executionPlan.filter(node, DEPENDS_ON, null);t.hasNext();){
                Resource o = t.next().getObject();
                if(o instanceof NonLiteral){
                    dependsOn.add((NonLiteral)o);
                } else {
                    throw new ChainException("Execution Node "+node+" defines the literal '" +
                        o+"' as value for the "+DEPENDS_ON +" property. However this" +
                        "property requires values to be bNodes or URIs.");
                }
            }
            nodeDependencies.put(node, dependsOn);
        }
        //2. now check the dependency graph
        for(Entry<NonLiteral,Collection<NonLiteral>> entry : nodeDependencies.entrySet()){
            if(entry.getValue() != null){
                for(NonLiteral dependent : entry.getValue()){
                    if(!nodeDependencies.containsKey(dependent)){
                        throw new ChainException("Execution Node "+entry.getKey()+
                            " defines a dependency to an non existent ex:ExectutionNode "+
                            dependent+"!");
                    } //else the dependency is valid
                }
            } //no dependencies
View Full Code Here

   
    @Override
    public void enhanceContent(ContentItem ci) throws EngineException, ChainException {
        Chain defaultChain = chainManager.getDefault();
        if(defaultChain == null){
            throw new ChainException("Unable to enhance ContentItem '"+ci.getUri()+
                "' because currently no enhancement chain is active. Please" +
                "configure a Chain or enable the default chain");
        }
        enhanceContent(ci, defaultChain);
    }
View Full Code Here

            StringBuilder sb = new StringBuilder("Status:\n");
            ExecutionMetadata em = ExecutionMetadata.parseFrom(job.getExecutionMetadata(), ci.getUri());
            for(Entry<String,Execution> ex : em.getEngineExecutions().entrySet()){
                sb.append("  -").append(ex.getKey()).append(": ").append(ex.getValue().getStatus()).append('\n');
            }
            throw new ChainException("Execution timeout after "
                    +((System.currentTimeMillis()-start)/1000f)+"sec (timeout:"+(maxEnhancementJobWaitTime/1000)
                + "sec) for ContentItem "+ci.getUri()+"\n"+sb.toString()
                + " \n To change the timeout change value of property '"+
                    MAX_ENHANCEMENT_JOB_WAIT_TIME+"' for the service "+getClass());
        }
        log.debug("Execution of Chain {} {} after {}ms for ContentItem {}",
                new Object[]{ chain.getName(), job.isFailed() ? "failed" : "finished",
                        System.currentTimeMillis()-start,
                        job.getContentItem().getUri()});
        //NOTE: ExecutionMetadata are not added to the metadata of the ContentItem
        //      by the EnhancementJobManager.
        //      However one could add this as an optional feature to the
        //      RESTful interface of the Enhancer!
        //ci.getMetadata().addAll(job.getExecutionMetadata());
        if(job.isFailed()){
          Exception e = job.getError();
            EnhancementJobHandler.logJobInfo(enhancementJobManagerLog, job,
                "-- log information about failed EnhancementJob --", true);
            logExecutionMetadata(job);
            log.warn("ExecutionMetadata: ");
            for(Iterator<Triple> it = job.getExecutionMetadata().iterator();
                    it.hasNext();
                    log.warn(it.next().toString()));
          if (e instanceof SecurityException) {
            throw (SecurityException)e;
          } else {
            throw new ChainException(job.getErrorMessage(), e);
          }
        }
        if(!job.isFinished()){
            log.warn("Execution finished, but Job is not finished!");
            EnhancementJobHandler.logJobInfo(log, job, null, true);
            logExecutionMetadata(job);
            throw new ChainException("EnhancementJobManager was deactivated while" +
                " enhancing the passed ContentItem "+job.getContentItem()+
                " (EnhancementJobManager type: "+getClass()+")");
        } else {
          //log infos about the execution times to the enhancementJobManager
          EnhancementJobHandler.logExecutionTimes(enhancementJobManagerLog, job);
View Full Code Here

    }
   
    private void update() throws ChainException {
        Set<String> activeEngineNames = new HashSet<String>(tracker.getActiveEngineNames());
        if(activeEngineNames.isEmpty()){
            throw new ChainException("Currently there are no active EnhancementEngines available");
        }
        List<EnhancementEngine> activeEngines = new ArrayList<EnhancementEngine>(activeEngineNames.size());
        Iterator<String> names = activeEngineNames.iterator();
        while(names.hasNext()){
            String name = names.next();
View Full Code Here

   
    @Override
    public void enhanceContent(ContentItem ci) throws EngineException, ChainException {
        Chain defaultChain = chainManager.getDefault();
        if(defaultChain == null){
            throw new ChainException("Unable to enhance ContentItem '"+ci.getUri()+
                "' because currently no enhancement chain is active. Please" +
                "configure a Chain or enable the default chain");
        }
        enhanceContent(ci, defaultChain);
    }
View Full Code Here

            StringBuilder sb = new StringBuilder("Status:\n");
            ExecutionMetadata em = ExecutionMetadata.parseFrom(job.getExecutionMetadata(), ci.getUri());
            for(Entry<String,Execution> ex : em.getEngineExecutions().entrySet()){
                sb.append("  -").append(ex.getKey()).append(": ").append(ex.getValue().getStatus()).append('\n');
            }
            throw new ChainException("Execution timeout after "
                    +((System.currentTimeMillis()-start)/1000f)+"sec (timeout:"+(maxEnhancementJobWaitTime/1000)
                + "sec) for ContentItem "+ci.getUri()+"\n"+sb.toString()
                + " \n To change the timeout change value of property '"+
                    MAX_ENHANCEMENT_JOB_WAIT_TIME+"' for the service "+getClass());
        }
        log.info("Execution of Chain {} {} after {}ms for ContentItem {}",
            new Object[]{ chain.getName(), job.isFailed() ? "failed" : "finished",
                    System.currentTimeMillis()-start,
                    job.getContentItem().getUri()});
        //NOTE: ExecutionMetadata are not added to the metadata of the ContentItem
        //      by the EnhancementJobManager.
        //      However one could add this as an optional feature to the
        //      RESTful interface of the Enhancer!
        //ci.getMetadata().addAll(job.getExecutionMetadata());
        if(job.isFailed()){
          Exception e = job.getError();
          if (e instanceof SecurityException) {
            throw (SecurityException)e;
          } else {
            throw new ChainException(job.getErrorMessage(), e);
          }
        }
        if(!job.isFinished()){
            log.warn("Execution finished, but Job is not finished!");
            EnhancementJobHandler.logJobInfo(log, job, null, true);
            log.warn("ExecutionMetadata: ");
            for(Iterator<Triple> it = job.getExecutionMetadata().iterator();
                    it.hasNext();
                    log.warn(it.next().toString()));
            throw new ChainException("EnhancementJobManager was deactivated while" +
                " enhancing the passed ContentItem "+job.getContentItem()+
                " (EnhancementJobManager type: "+getClass()+")");
        }
    }
View Full Code Here

        //1. check the ExecutionNodes
        while(executionNodeIt.hasNext()){
            NonLiteral node = executionNodeIt.next().getSubject();
            Iterator<String> engines = EnhancementEngineHelper.getStrings(executionPlan, node,ENGINE);
            if(!engines.hasNext()){
                throw new ChainException("Execution Node "+node+" does not define " +
                        "the required property "+ENGINE+"!");
            }
            String engine = engines.next();
            if(engines.hasNext()){
                throw new ChainException("Execution Node "+node+" does not define " +
                        "multiple values for the property "+ENGINE+"!");
            }
            if(engine.isEmpty()){
                throw new ChainException("Execution Node "+node+" does not define " +
                        "an empty String as engine name (property "+ENGINE+")!");
            }
            engineNames.add(engine);
            Collection<NonLiteral> dependsOn = new HashSet<NonLiteral>();
            for(Iterator<Triple> t = executionPlan.filter(node, DEPENDS_ON, null);t.hasNext();){
                Resource o = t.next().getObject();
                if(o instanceof NonLiteral){
                    dependsOn.add((NonLiteral)o);
                } else {
                    throw new ChainException("Execution Node "+node+" defines the literal '" +
                        o+"' as value for the "+DEPENDS_ON +" property. However this" +
                        "property requires values to be bNodes or URIs.");
                }
            }
            nodeDependencies.put(node, dependsOn);
        }
        //2. now check the dependency graph
        for(Entry<NonLiteral,Collection<NonLiteral>> entry : nodeDependencies.entrySet()){
            if(entry.getValue() != null){
                for(NonLiteral dependent : entry.getValue()){
                    if(!nodeDependencies.containsKey(dependent)){
                        throw new ChainException("Execution Node "+entry.getKey()+
                            " defines a dependency to an non existent ex:ExectutionNode "+
                            dependent+"!");
                    } //else the dependency is valid
                }
            } //no dependencies
View Full Code Here

    }
   
    private void update() throws ChainException {
        Set<String> activeEngineNames = new HashSet<String>(tracker.getActiveEngineNames());
        if(activeEngineNames.isEmpty()){
            throw new ChainException("Currently there are no active EnhancementEngines available");
        }
        List<EnhancementEngine> activeEngines = new ArrayList<EnhancementEngine>(activeEngineNames.size());
        Iterator<String> names = activeEngineNames.iterator();
        while(names.hasNext()){
            String name = names.next();
View Full Code Here

   
    @Override
    public void enhanceContent(ContentItem ci) throws EngineException, ChainException {
        Chain defaultChain = chainManager.getDefault();
        if(defaultChain == null){
            throw new ChainException("Unable to enhance ContentItem '"+ci.getUri()+
                "' because currently no enhancement chain is active. Please" +
                "configure a Chain or enable the default chain");
        }
        enhanceContent(ci, defaultChain);
    }
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.servicesapi.ChainException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.