Package org.opencastproject.execute.api

Examples of org.opencastproject.execute.api.ExecuteException


      if (response != null) {
        Job job = JobParser.parseJob(response.getEntity().getContent());
        logger.info("Completing execution of command {} using a remote execute service", exec);
        return job;
      } else
        throw new ExecuteException(String.format("Failed to execute the command %s using a remote execute service", exec));

    } catch (MediaPackageException e) {
      throw new ExecuteException("Error serializing the MediaPackage element", e);
    } catch (IllegalStateException e) {
      throw new ExecuteException(e);
    } catch (IOException e) {
      throw new ExecuteException(e);
    } finally {
      closeConnection(response);
    }
  }
View Full Code Here


        Job job = JobParser.parseJob(response.getEntity().getContent());
        logger.info("Completing execution of command {} using a remote execute service", exec);
        return job;
      } else {
        logger.error("Failed to execute the command {} using a remote execute service", exec);
        throw new ExecuteException(String.format("Failed to execute the command %s using a remote execute service", exec));
      }
    } catch (IllegalStateException e) {
      throw new ExecuteException(e);
    } catch (IOException e) {
      throw new ExecuteException(e);
    } finally {
      closeConnection(response);
    }
  }
View Full Code Here

          // Have the track inspected and return the result
          Job inspectionJob = null;
          inspectionJob = inspectionService.inspect(resultElement.getURI());
          JobBarrier barrier = new JobBarrier(serviceRegistry, inspectionJob);
          if (!barrier.waitForJobs().isSuccess()) {
            throw new ExecuteException("Media inspection of " + resultElement.getURI() + " failed");
          }

          resultElement = MediaPackageElementParser.getFromXml(inspectionJob.getPayload());
        }
View Full Code Here

      paramList.add((expectedType == null) ? null : expectedType.toString());

      return serviceRegistry.createJob(JOB_TYPE, Operation.Execute_Element.toString(), paramList);

    } catch (ServiceRegistryException e) {
      throw new ExecuteException(String.format("Unable to create a job of type '%s'", JOB_TYPE), e);
    } catch (MediaPackageException e) {
      throw new ExecuteException("Error serializing an element", e);
    }
  }
View Full Code Here

      paramList.add(outFileName);
      paramList.add((expectedType == null) ? null : expectedType.toString());

      return serviceRegistry.createJob(JOB_TYPE, Operation.Execute_Mediapackage.toString(), paramList);
    } catch (ServiceRegistryException e) {
      throw new ExecuteException(String.format("Unable to create a job of type '%s'", JOB_TYPE), e);
    }
  }
View Full Code Here

  protected String process(Job job) throws ExecuteException {
    List<String> arguments = new ArrayList<String>(job.getArguments());

    // Check this operation is allowed
    if (!allowedCommands.isEmpty() && !allowedCommands.contains(arguments.get(0)))
      throw new ExecuteException("Command '" + arguments.get(0) + "' is not allowed");

    String outFileName = null;
    String strAux = null;
    MediaPackage mp = null;
    Type expectedType = null;
    MediaPackageElement element = null;
    Operation op = null;

    try {
      op = Operation.valueOf(job.getOperation());

      switch (arguments.size()) {
        case 5:
          strAux = arguments.remove(4);
          expectedType = (strAux == null) ? null : Type.valueOf(strAux);
          outFileName = StringUtils.trimToNull(arguments.remove(3));
          if (((outFileName != null) && (expectedType == null)) || ((outFileName == null) && (expectedType != null)))
            throw new ExecuteException("The output type and filename must be both specified");
          outFileName = (outFileName == null) ? null : job.getId() + "_" + outFileName;

        case 3:
          switch (op) {
            case Execute_Mediapackage:
              mp = MediaPackageParser.getFromXml(arguments.remove(2));
              return doProcess(arguments, mp, outFileName, expectedType);
            case Execute_Element:
              element = MediaPackageElementParser.getFromXml(arguments.remove(2));
              return doProcess(arguments, element, outFileName, expectedType);
            default:
              throw new IllegalStateException("Don't know how to handle operation '" + job.getOperation() + "'");
          }

        default:
          throw new IndexOutOfBoundsException("Incorrect number of parameters for operation execute_" + op + ": "
                  + arguments.size());
      }

    } catch (MediaPackageException e) {
      throw new ExecuteException("Error unmarshalling the input mediapackage/element", e);
    } catch (IllegalArgumentException e) {
      throw new ExecuteException("This service can't handle operations of type '" + op + "'", e);
    } catch (IndexOutOfBoundsException e) {
      throw new ExecuteException("The argument list for operation '" + op + "' does not meet expectations", e);
    }
  }
View Full Code Here

        if (matcher.group(1).equals("id")) {
          matcher.appendReplacement(sb, mp.getIdentifier().toString());
        } else if (matcher.group(1).equals("flavor")) {
          elementsByFlavor = mp.getElementsByFlavor(MediaPackageElementFlavor.parseFlavor(matcher.group(2)));
          if (elementsByFlavor.length == 0)
            throw new ExecuteException("No elements in the MediaPackage match the flavor '" + matcher.group(1) + "'.");

          if (elementsByFlavor.length > 1)
            logger.warn("Found more than one element with flavor '{}'. Using {} by default...", matcher.group(1),
                    elementsByFlavor[0].getIdentifier());

          File elementFile = workspace.get(elementsByFlavor[0].getURI());
          matcher.appendReplacement(sb, elementFile.getAbsolutePath());
        } else if (matcher.group(1).equals("out")) {
          matcher.appendReplacement(sb, outFile.getAbsolutePath());
        } else if (properties.get(matcher.group(1)) != null) {
          matcher.appendReplacement(sb, (String) properties.get(matcher.group(1)));
        } else if (bundleContext.getProperty(matcher.group(1)) != null) {
          matcher.appendReplacement(sb, bundleContext.getProperty(matcher.group(1)));
        }
      }
      matcher.appendTail(sb);
      params = sb.toString();
    } catch (IllegalArgumentException e) {
      throw new ExecuteException("Tag 'flavor' must specify a valid MediaPackage element flavor.", e);
    } catch (NotFoundException e) {
      throw new ExecuteException("The element '" + elementsByFlavor[0].getURI().toString()
              + "' does not exist in the workspace.", e);
    } catch (IOException e) {
      throw new ExecuteException("Error retrieving MediaPackage element from workspace: '"
              + elementsByFlavor[0].getURI().toString() + "'.", e);
    }

    arguments.addAll(splitParameters(params));
View Full Code Here

          if (outFile != null) {
            arguments.set(i, arguments.get(i).replace(OUTPUT_FILE_PATTERN, outFile.getAbsolutePath()));
            continue;
          } else {
            logger.error("{} pattern found, but no valid output filename was specified", OUTPUT_FILE_PATTERN);
            throw new ExecuteException(OUTPUT_FILE_PATTERN
                    + " pattern found, but no valid output filename was specified");
          }
        }
      }

      return runCommand(arguments, outFile, expectedType);

    } catch (IOException e) {
      logger.error("Error retrieving file from workspace: {}", element.getURI());
      throw new ExecuteException("Error retrieving file from workspace: " + element.getURI(), e);
    } catch (NotFoundException e) {
      logger.error("Element '{}' cannot be found in the workspace.", element.getURI());
      throw new ExecuteException("Element " + element.getURI() + " cannot be found in the workspace");
    }
  }
View Full Code Here

          line = new Scanner(p.getInputStream()).useDelimiter("\\A").next();
        } catch (NoSuchElementException e) {
          line = "";
        }

        throw new ExecuteException(String.format("Process %s returned error code %d with this output:\n%s",
                arguments.get(0), result, line.trim()));
      }
    } catch (InterruptedException e) {
      throw new ExecuteException("The executor thread has been unexpectedly interrupted", e);
    } catch (IOException e) {
      // Only log the first argument, the executable, as other arguments may contain sensitive values
      // e.g. MySQL password/user, paths, etc. that should not be shown to caller
      logger.error("Could not start subprocess {}", arguments.get(0));
      throw new ExecuteException("Could not start subprocess: " + arguments.get(0), e);
    } catch (UnsupportedElementException e) {
      throw new ExecuteException("Couldn't create a new MediaPackage element of type " + expectedType.toString(), e);
    } catch (ConfigurationException e) {
      throw new ExecuteException("Couldn't instantiate a new MediaPackage element builder", e);
    } catch (MediaPackageException e) {
      throw new ExecuteException("Couldn't serialize a new Mediapackage element of type " + expectedType.toString(), e);
    } finally {
      IoSupport.closeQuietly(p);
    }
  }
View Full Code Here

TOP

Related Classes of org.opencastproject.execute.api.ExecuteException

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.