Search in sources :

Example 1 with Serving

use of io.hops.hopsworks.persistence.entity.serving.Serving in project hopsworks by logicalclocks.

the class ServingUtil method validatePythonUserInput.

private void validatePythonUserInput(Serving serving) throws IllegalArgumentException, ServingException {
    // Check model files and/or python scripts
    try {
        List<Inode> children = inodeController.getChildren(serving.getModelVersionPath());
        long modelFiles = children.stream().filter(c -> {
            String name = c.getInodePK().getName();
            return MODEL_FILE_EXTS.stream().anyMatch(name::endsWith);
        }).count();
        if (modelFiles == 0) {
            // if no model files found
            if (children.stream().noneMatch(c -> c.getInodePK().getName().endsWith(".py"))) {
                // and no python script
                throw new ServingException(RESTCodes.ServingErrorCode.MODEL_FILES_STRUCTURE_NOT_VALID, Level.FINE, "Model" + " path requires either a python script or model file (i.e., joblib or pickle files)");
            }
        }
    } catch (FileNotFoundException e) {
        throw new ServingException(RESTCodes.ServingErrorCode.MODEL_PATH_NOT_FOUND, Level.FINE, null);
    }
    if (serving.isBatchingEnabled()) {
        throw new ServingException(RESTCodes.ServingErrorCode.REQUEST_BATCHING_NOT_SUPPORTED, Level.SEVERE, "Request " + "batching is not supported in Python deployments");
    }
}
Also used : InodeController(io.hops.hopsworks.common.hdfs.inode.InodeController) StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) ServingFacade(io.hops.hopsworks.common.dao.serving.ServingFacade) Project(io.hops.hopsworks.persistence.entity.project.Project) Level(java.util.logging.Level) ProjectTopicsFacade(io.hops.hopsworks.common.dao.kafka.ProjectTopicsFacade) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) Settings(io.hops.hopsworks.common.util.Settings) Matcher(java.util.regex.Matcher) ServingWrapper(io.hops.hopsworks.common.serving.ServingWrapper) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) ModelServer(io.hops.hopsworks.persistence.entity.serving.ModelServer) Utils(io.hops.hopsworks.common.hdfs.Utils) EJB(javax.ejb.EJB) TopicDTO(io.hops.hopsworks.common.dao.kafka.TopicDTO) Stateless(javax.ejb.Stateless) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects) Stream(java.util.stream.Stream) Serving(io.hops.hopsworks.persistence.entity.serving.Serving) ServingException(io.hops.hopsworks.exceptions.ServingException) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) ServingException(io.hops.hopsworks.exceptions.ServingException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with Serving

use of io.hops.hopsworks.persistence.entity.serving.Serving in project hopsworks by logicalclocks.

the class ServingUtil method validateUserInput.

/**
 * Validates user input before creating or updating a serving. This method contains the common input validation
 * between different serving types and then delegates to serving-type-specific controllers to do validation specific
 * to the serving type.
 *
 * @param servingWrapper contains the user-data to validate
 * @param project the project where the serving resides
 * @throws ServingException
 * @throws java.io.UnsupportedEncodingException
 */
public void validateUserInput(ServingWrapper servingWrapper, Project project) throws ServingException, UnsupportedEncodingException {
    Serving serving = servingWrapper.getServing();
    Serving dbServing = servingFacade.findByProjectAndName(project, serving.getName());
    setDefaultRequestBatching(serving);
    // NOTE: order matters
    validateServingName(serving, dbServing);
    validateModelPath(serving);
    validateModelVersion(serving);
    validateModelServer(serving, dbServing);
    validateModelName(serving);
    validateServingTool(serving);
    validatePredictor(project, serving);
    validateKafkaTopicSchema(project, serving, servingWrapper.getKafkaTopicDTO());
    validateInstances(serving);
}
Also used : Serving(io.hops.hopsworks.persistence.entity.serving.Serving)

Example 3 with Serving

use of io.hops.hopsworks.persistence.entity.serving.Serving in project hopsworks by logicalclocks.

the class ServingFacade method updateDbObject.

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Serving updateDbObject(Serving newServing, Project project) throws ServingException {
    // Update request - execute this code within a transaction
    // Merge serving fields
    Serving oldDbServing = findByProjectAndId(project, newServing.getId());
    Serving dbServing = mergeServings(oldDbServing, newServing);
    // Update entity in the db
    return merge(dbServing);
}
Also used : Serving(io.hops.hopsworks.persistence.entity.serving.Serving) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 4 with Serving

use of io.hops.hopsworks.persistence.entity.serving.Serving in project hopsworks by logicalclocks.

the class LocalhostServingController method deleteAll.

/**
 * Deletes all servings in a project (used for project cleanup)
 *
 * @param project the project to delete all servings for
 * @throws ServingException thrown if a lock for getting the serving could not be acquired
 */
@Override
public void deleteAll(Project project) throws ServingException {
    List<Serving> servingList = servingFacade.findForProject(project);
    for (Serving serving : servingList) {
        // Acquire lock
        servingFacade.acquireLock(project, serving.getId());
        ServingStatusEnum status = getServingStatus(serving);
        // If we reached this point, we just acquired a lock
        if (!status.equals(ServingStatusEnum.STARTING)) {
            killServingInstance(project, serving, false);
        }
        servingFacade.delete(serving);
    }
}
Also used : Serving(io.hops.hopsworks.persistence.entity.serving.Serving)

Example 5 with Serving

use of io.hops.hopsworks.persistence.entity.serving.Serving in project hopsworks by logicalclocks.

the class LocalhostServingController method startOrStop.

/**
 * Starts or stop a serving instance (depending on the user command). Will call the controller for the corresponding
 * model server, such as Tensorflow Serving or Python
 *
 * @param project the project where the serving resides
 * @param user the user making the request
 * @param servingId the id of the serving
 * @param command the command (start or stop)
 * @throws ServingException if the serving could not be started or lock could be acquired
 */
@Override
public void startOrStop(Project project, Users user, Integer servingId, ServingCommands command) throws ServingException {
    Serving serving = servingFacade.acquireLock(project, servingId);
    ServingStatusEnum currentStatus = getServingStatus(serving);
    // If we reached this point, we just acquired a lock
    if (currentStatus == ServingStatusEnum.STARTING && command == ServingCommands.START) {
        startServingInstance(project, user, serving);
    // getServingStatus returns UPDATING if the PID is different than -2 and there is a lock.
    // If we reached this point, we just acquired a lock
    } else if (currentStatus == ServingStatusEnum.UPDATING && command == ServingCommands.STOP) {
        killServingInstance(project, serving, true);
    } else {
        // Release lock before throwing the exception
        servingFacade.releaseLock(project, servingId);
        String userMsg = "Instance is already " + (command == ServingCommands.START ? ServingStatusEnum.STARTED.toString() : ServingStatusEnum.STOPPED.toString()).toLowerCase();
        throw new ServingException(RESTCodes.ServingErrorCode.LIFECYCLEERROR, Level.FINE, userMsg);
    }
}
Also used : Serving(io.hops.hopsworks.persistence.entity.serving.Serving) ServingException(io.hops.hopsworks.exceptions.ServingException)

Aggregations

Serving (io.hops.hopsworks.persistence.entity.serving.Serving)13 ServingException (io.hops.hopsworks.exceptions.ServingException)5 TransactionAttribute (javax.ejb.TransactionAttribute)3 ServingWrapper (io.hops.hopsworks.common.serving.ServingWrapper)2 LockTimeoutException (javax.persistence.LockTimeoutException)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 Strings (com.google.common.base.Strings)1 ProjectTopicsFacade (io.hops.hopsworks.common.dao.kafka.ProjectTopicsFacade)1 TopicDTO (io.hops.hopsworks.common.dao.kafka.TopicDTO)1 ServingFacade (io.hops.hopsworks.common.dao.serving.ServingFacade)1 Utils (io.hops.hopsworks.common.hdfs.Utils)1 InodeController (io.hops.hopsworks.common.hdfs.inode.InodeController)1 InferenceLogger (io.hops.hopsworks.common.serving.inference.logger.InferenceLogger)1 ProcessDescriptor (io.hops.hopsworks.common.util.ProcessDescriptor)1 ProcessResult (io.hops.hopsworks.common.util.ProcessResult)1 Settings (io.hops.hopsworks.common.util.Settings)1 ApiKeyException (io.hops.hopsworks.exceptions.ApiKeyException)1 InferenceException (io.hops.hopsworks.exceptions.InferenceException)1 Inode (io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)1 ProjectTopics (io.hops.hopsworks.persistence.entity.kafka.ProjectTopics)1