Search in sources :

Example 1 with TensorBoardDTO

use of io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardDTO in project hopsworks by logicalclocks.

the class TensorBoardResource method startTensorBoard.

@ApiOperation(value = "Start a new TensorBoard", response = TensorBoardDTO.class)
@POST
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response startTensorBoard(@Context SecurityContext sc, @Context UriInfo uriInfo) throws DatasetException, ProjectException, TensorBoardException, UnsupportedEncodingException, ServiceDiscoveryException {
    DsPath dsPath = pathValidator.validatePath(this.project, "Experiments/" + experimentId);
    String fullPath = dsPath.getFullPath().toString();
    Users user = jWTHelper.getUserPrincipal(sc);
    TensorBoardDTO tensorBoardDTO = tensorBoardController.startTensorBoard(experimentId, project, user, fullPath);
    waitForTensorBoardLoaded(tensorBoardDTO);
    UriBuilder builder = uriInfo.getAbsolutePathBuilder();
    return Response.created(builder.build()).entity(tensorBoardDTO).build();
}
Also used : TensorBoardDTO(io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardDTO) DsPath(io.hops.hopsworks.api.project.util.DsPath) Users(io.hops.hopsworks.persistence.entity.user.Users) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 2 with TensorBoardDTO

use of io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardDTO in project hopsworks by logicalclocks.

the class TensorBoardResource method stopTensorBoard.

@ApiOperation("Stop the running TensorBoard")
@DELETE
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response stopTensorBoard(@Context SecurityContext sc) throws TensorBoardException {
    Users user = jWTHelper.getUserPrincipal(sc);
    TensorBoardDTO tbDTO = tensorBoardController.getTensorBoard(project, user);
    if (tbDTO == null) {
        return Response.noContent().build();
    }
    tensorBoardController.cleanup(this.project, user);
    return Response.noContent().build();
}
Also used : TensorBoardDTO(io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardDTO) Users(io.hops.hopsworks.persistence.entity.user.Users) DELETE(javax.ws.rs.DELETE) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 3 with TensorBoardDTO

use of io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardDTO in project hopsworks by logicalclocks.

the class TensorBoardController method startTensorBoard.

/**
 * Start the TensorBoard for the specific user in this project with the specified elasticId containing the logdir
 * @param mlId
 * @param project
 * @param user
 * @param tensorBoardLogdir
 * @return
 * @throws IOException
 */
public TensorBoardDTO startTensorBoard(String mlId, Project project, Users user, String tensorBoardLogdir) throws TensorBoardException, ServiceDiscoveryException {
    tensorBoardLogdir = prependNameNode(tensorBoardLogdir);
    TensorBoardDTO tensorBoardDTO = null;
    TensorBoard tb = tensorBoardFacade.findForProjectAndUser(project, user);
    if (tb != null) {
        cleanup(tb);
    }
    String hdfsUsername = hdfsUsersController.getHdfsUserName(project, user);
    HdfsUsers hdfsUser = hdfsUsersFacade.findByName(hdfsUsername);
    String tensorBoardDirectory = DigestUtils.sha256Hex(Integer.toString(ThreadLocalRandom.current().nextInt()));
    tensorBoardDTO = tensorBoardProcessMgr.startTensorBoard(project, user, hdfsUser, tensorBoardLogdir, tensorBoardDirectory);
    Date lastAccessed = new Date();
    tensorBoardDTO.setMlId(mlId);
    tensorBoardDTO.setLastAccessed(lastAccessed);
    tensorBoardDTO.setHdfsLogdir(tensorBoardLogdir);
    TensorBoard newTensorBoard = new TensorBoard();
    TensorBoardPK tensorBoardPK = new TensorBoardPK();
    tensorBoardPK.setProjectId(project.getId());
    tensorBoardPK.setUserId(user.getUid());
    newTensorBoard.setTensorBoardPK(tensorBoardPK);
    newTensorBoard.setCid(tensorBoardDTO.getCid());
    newTensorBoard.setEndpoint(tensorBoardDTO.getEndpoint());
    newTensorBoard.setHdfsUserId(hdfsUser.getId());
    newTensorBoard.setMlId(mlId);
    newTensorBoard.setLastAccessed(lastAccessed);
    newTensorBoard.setHdfsLogdir(tensorBoardLogdir);
    newTensorBoard.setSecret(tensorBoardDirectory);
    tensorBoardFacade.persist(newTensorBoard);
    return tensorBoardDTO;
}
Also used : TensorBoardPK(io.hops.hopsworks.persistence.entity.tensorflow.TensorBoardPK) TensorBoardDTO(io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardDTO) TensorBoard(io.hops.hopsworks.persistence.entity.tensorflow.TensorBoard) HdfsUsers(io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers) Date(java.util.Date)

Example 4 with TensorBoardDTO

use of io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardDTO in project hopsworks by logicalclocks.

the class TensorBoardController method getTensorBoard.

/**
 * Fetch the TensorBoard from the database for the user in this project
 * @param project
 * @param user
 * @return
 */
public TensorBoardDTO getTensorBoard(Project project, Users user) {
    TensorBoard tb;
    tb = tensorBoardFacade.findForProjectAndUser(project, user);
    if (tb == null) {
        return null;
    }
    tb.setLastAccessed(new Date());
    tensorBoardFacade.update(tb);
    return new TensorBoardDTO(tb);
}
Also used : TensorBoardDTO(io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardDTO) TensorBoard(io.hops.hopsworks.persistence.entity.tensorflow.TensorBoard) Date(java.util.Date)

Example 5 with TensorBoardDTO

use of io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardDTO in project hopsworks by logicalclocks.

the class TensorBoardResource method getTensorBoard.

@ApiOperation(value = "Get the TensorBoard", response = TensorBoardDTO.class)
@GET
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getTensorBoard(@Context SecurityContext sc) throws TensorBoardException {
    try {
        Users user = jWTHelper.getUserPrincipal(sc);
        TensorBoardDTO tbDTO = tensorBoardController.getTensorBoard(project, user);
        if (tbDTO == null) {
            throw new TensorBoardException(RESTCodes.TensorBoardErrorCode.TENSORBOARD_NOT_FOUND, Level.FINE);
        }
        return Response.ok().entity(tbDTO).build();
    } catch (PersistenceException pe) {
        throw new TensorBoardException(RESTCodes.TensorBoardErrorCode.TENSORBOARD_FETCH_ERROR, Level.SEVERE, null, pe.getMessage(), pe);
    }
}
Also used : TensorBoardDTO(io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardDTO) PersistenceException(javax.persistence.PersistenceException) Users(io.hops.hopsworks.persistence.entity.user.Users) TensorBoardException(io.hops.hopsworks.exceptions.TensorBoardException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Aggregations

TensorBoardDTO (io.hops.hopsworks.common.dao.tensorflow.config.TensorBoardDTO)6 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)3 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)3 TensorBoard (io.hops.hopsworks.persistence.entity.tensorflow.TensorBoard)3 Users (io.hops.hopsworks.persistence.entity.user.Users)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Date (java.util.Date)2 Produces (javax.ws.rs.Produces)2 DsPath (io.hops.hopsworks.api.project.util.DsPath)1 TensorBoardException (io.hops.hopsworks.exceptions.TensorBoardException)1 HdfsUsers (io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers)1 TensorBoardPK (io.hops.hopsworks.persistence.entity.tensorflow.TensorBoardPK)1 PersistenceException (javax.persistence.PersistenceException)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 UriBuilder (javax.ws.rs.core.UriBuilder)1