Skip to content

Commit

Permalink
Cleaned up formatting, scoping
Browse files Browse the repository at this point in the history
  • Loading branch information
zack-rma committed Dec 18, 2024
1 parent 2fc5733 commit 14aa521
Show file tree
Hide file tree
Showing 2 changed files with 323 additions and 293 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,21 @@ public Response getApp(@QueryParam("appid") Long appId)
throws WebAppException, DbException
{
if (appId == null)
{
throw new WebAppException(HttpServletResponse.SC_BAD_REQUEST,
"Missing required appid parameter.");
}
try (LoadingAppDAI dai = getLegacyDatabase().makeLoadingAppDAO())
{
return Response.status(HttpServletResponse.SC_OK)
.entity(map(dai.getComputationApp(DbKey.createDbKey(appId)))).build();
}
catch(NoSuchObjectException | DbIoException ex)
catch (NoSuchObjectException e)
{
return Response.status(HttpServletResponse.SC_NOT_FOUND)
.entity("No such app found with ID " + appId).build();
}
catch (DbIoException ex)
{
throw new DbException("No such app with ID " + appId, ex);
}
Expand Down Expand Up @@ -156,6 +163,10 @@ static CompAppInfo map(ApiLoadingApp app)
{
ret.setAppId(DbKey.createDbKey(app.getAppId()));
}
else
{
ret.setAppId(DbKey.NullKey);
}
ret.setAppName(app.getAppName());
ret.setComment(app.getComment());
ret.setLastModified(app.getLastModified());
Expand Down Expand Up @@ -193,7 +204,12 @@ public Response deleteApp(@QueryParam("appid") Long appId)
return Response.status(HttpServletResponse.SC_OK)
.entity("appId with ID " + appId + " deleted").build();
}
catch (NoSuchObjectException | DbIoException | ConstraintException ex)
catch (NoSuchObjectException e)
{
return Response.status(HttpServletResponse.SC_NOT_FOUND)
.entity("No such app found with ID " + appId).build();
}
catch (DbIoException | ConstraintException ex)
{
throw new DbException(String.format("No such app with ID: %s", appId), ex);
}
Expand All @@ -203,7 +219,7 @@ public Response deleteApp(@QueryParam("appid") Long appId)
@Path("appstat")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({AuthorizationCheck.ODCS_API_ADMIN, AuthorizationCheck.ODCS_API_USER})
public Response getAppStat() throws DbException
public Response getAppStatus() throws DbException
{
try (LoadingAppDAI dai = getLegacyDatabase().makeLoadingAppDAO())
{
Expand Down Expand Up @@ -323,7 +339,10 @@ public Response postAppStart(@QueryParam("appid") Long appId)
throws WebAppException, DbException
{
if (appId == null)
throw new WebAppException(HttpServletResponse.SC_BAD_REQUEST, "appId parameter required for this operation.");
{
throw new WebAppException(HttpServletResponse.SC_BAD_REQUEST,
"appId parameter required for this operation.");
}

try (LoadingAppDAI dai = getLegacyDatabase().makeLoadingAppDAO())
{
Expand Down Expand Up @@ -374,7 +393,8 @@ public Response postAppStart(@QueryParam("appid") Long appId)
}
}

static ApiLoadingApp mapLoading(CompAppInfo app) {
static ApiLoadingApp mapLoading(CompAppInfo app)
{
ApiLoadingApp ret = new ApiLoadingApp();
ret.setAppId(app.getAppId().getValue());
ret.setAppName(app.getAppName());
Expand All @@ -395,7 +415,10 @@ public Response postAppStop(@QueryParam("appid") Long appId)
throws WebAppException, DbException
{
if (appId == null)
throw new WebAppException(HttpServletResponse.SC_BAD_REQUEST, "appId parameter required for this operation.");
{
throw new WebAppException(HttpServletResponse.SC_BAD_REQUEST,
"appId parameter required for this operation.");
}

try (LoadingAppDAI dai = getLegacyDatabase().makeLoadingAppDAO())
{
Expand All @@ -405,23 +428,30 @@ public Response postAppStop(@QueryParam("appid") Long appId)
ApiAppStatus appStat = getAppStatus(dai, appId);

if (appStat == null || appStat.getPid() == null)
{
throw new WebAppException(HttpServletResponse.SC_NOT_FOUND,
"appId " + appId + "(" + loadingApp.getAppName() + ") not currently running.");
}

dai.releaseCompProcLock(new TsdbCompLock(DbKey.createDbKey(appId), appStat.getPid().intValue(),
appStat.getHostname(), appStat.getHeartbeat(), appStat.getStatus()));

return Response.status(HttpServletResponse.SC_OK)
.entity("App with ID " + appId + " (" + loadingApp.getAppName() + ") terminated.").build();
}
catch (DbIoException | NoSuchObjectException ex)
catch (NoSuchObjectException e)
{
return Response.status(HttpServletResponse.SC_NOT_FOUND)
.entity("No such app found with ID " + appId).build();
}
catch (DbIoException ex)
{
throw new WebAppException(ErrorCodes.DATABASE_ERROR,
String.format("Error attempting to stop appId=%s", appId), ex);
}
}

static ApiAppStatus getAppStatus(LoadingAppDAI dai, Long appId) throws DbException
private static ApiAppStatus getAppStatus(LoadingAppDAI dai, Long appId) throws DbException
{
try
{
Expand Down
Loading

0 comments on commit 14aa521

Please sign in to comment.