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();
}
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();
}
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;
}
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);
}
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);
}
}
Aggregations