use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class DeploymentListingsBacking method process.
public Collection<ProcessingEvent> process(ProcessingContext context, Map<Object, Object> templateVariables, Map<Object, Object> parameterMap) {
List<ProcessingEvent> events = new ArrayList<ProcessingEvent>();
templateVariables.put(FormConstants.PROCESS_TARGET, PROCESS_TARGET);
String appId = firstValue(FormConstants.APP_ID, parameterMap);
String appVerId = firstValue("versionId", parameterMap);
String deploymentType = firstValue("deploymentType", parameterMap);
String processTarget = firstValue(FormConstants.PROCESS_TARGET, parameterMap);
Application app = null;
try {
app = modelManager.getModelService().findByPrimaryKey(Application.class, Long.valueOf(appId));
} catch (NumberFormatException nfe) {
events.add(new MessagesEvent("A valid applicationId must be supplied to either view or create deployments."));
}
events.add(new AddSubNavAnchorEvent(new Anchor("?bean=addModifyAppPage&applicationId=" + app.getId(), "View/Modify Application", "View/Modify Application")));
events.add(new AddSubNavAnchorEvent(new Anchor("?bean=appVersionListingsPage&applicationId=" + app.getId(), "Version Listings", "Version Listings")));
// TODO: I'm pretty sure I should create new deployments elsewhere and forward to here from there.
if (deploymentType != null && PROCESS_TARGET.compareTo(processTarget) == 0 && app != null) {
ApplicationVersion version = null;
try {
version = modelManager.getModelService().findByPrimaryKey(ApplicationVersion.class, Long.valueOf(appVerId));
} catch (NumberFormatException nfe) {
events.add(new MessagesEvent("A valid versionId must be supplied to create a deployment."));
}
if (version != null) {
Deployment depl = createDeployment(firstValue("userPrincipalName", parameterMap), version, deploymentType);
try {
modelManager.begin();
depl = modelManager.addModify(depl, events);
modelManager.commit(events);
events.add(new MessagesEvent("Deployment successfully completed."));
} catch (Exception pe) {
modelManager.rollback();
Throwable root = ExceptionUtils.getRootCause(pe);
events.add(new MessagesEvent(String.format("An exception was thrown creating the deployment: %s %s", root.getMessage(), ExceptionUtils.getStackTrace(root))));
}
}
}
// making sure to order the deployments by date
if (app != null && app.getDeployments() != null) {
List<Deployment> deployments = modelManager.getModelService().findDeploymentsByApplication(app);
Collections.sort(deployments, new Deployment.DateComparator());
templateVariables.put("deployments", deployments);
GlobalSettings settings = modelManager.getGlobalSettings();
Map<String, String> urls = new HashMap<String, String>();
for (Deployment depl : deployments) {
urls.put(depl.getApplicationArchive().getHash(), depl.getApplicationArchive().getDownloadUrl(settings));
}
templateVariables.put("deployments", deployments);
templateVariables.put("archiveUrls", urls);
}
return events;
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class WebViewServlet method service.
@SuppressWarnings("unchecked")
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
logger.trace("in service");
ModelManager mgr = getModelManager();
GlobalSettings settings = mgr.getGlobalSettings();
String validTempPath = settings.validateTemporaryStoragePath();
if (validTempPath != null) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, validTempPath);
}
String pathInfo = request.getPathInfo();
String[] pathParts = pathInfo.split("[/]");
if (pathParts.length < 4) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
String remove = pathParts[1] + "/" + pathParts[2] + "/" + pathParts[3];
String fileRelative = pathInfo.replace(remove, "");
String applicationNameString = URLDecoder.decode(pathParts[APP_NAME_INDEX], FormConstants.CHAR_ENC_DEFAULT);
String archiveHash = URLDecoder.decode(pathParts[APP_VER_INDEX], FormConstants.CHAR_ENC_DEFAULT);
Application app = mgr.getModelService().findApplicationByName(applicationNameString);
ApplicationArchive arch = mgr.getModelService().findApplicationArchiveByHashAndAlgorithm(app, archiveHash, "MD5");
String authSalt = app.getProxyAuthSalt();
String authToken = URLDecoder.decode(pathParts[AUTH_TOKEN_INDEX], FormConstants.CHAR_ENC_DEFAULT);
try {
if (!AuthTokenProvider.validateAuthToken(authSalt, authToken)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
}
} catch (DigestException e1) {
throw new GenericRuntimeException(e1);
}
File fileFull = new File(arch.getExplodedPath(settings.getTemporaryStoragePath()).getAbsolutePath() + "/" + fileRelative);
try {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String mimeType = fileNameMap.getContentTypeFor(fileFull.toURL().toString());
response.setContentType(mimeType);
response.setContentLength(Long.valueOf(fileFull.length()).intValue());
InputStream inputStream = null;
OutputStream outputStream = null;
try {
//response.setStatus(HttpServletResponse.SC_FOUND);
inputStream = new FileInputStream(fileFull);
outputStream = response.getOutputStream();
Utils.pipeInputStreamIntoOutputStream(inputStream, outputStream);
} finally {
if (inputStream != null) {
inputStream.close();
}
response.getOutputStream().flush();
response.getOutputStream().close();
}
} catch (FileNotFoundException e) {
logger.error("Exception {}", e);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} catch (IOException ioe) {
logger.error("Exception {}", ioe);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class AdminTest method testAddApplication.
public void testAddApplication() throws Exception {
Application app = new Application();
app.setName(APP_NAME);
app.setDescription(APP_DESC);
app.setDeploymentHistoryLength(APP_DEPL_LEN);
app.setVersionAdmins(APP_VERSION_ADMINS);
app.setAdmins(APP_ADMINS);
app.setInitialVersionIdentifier(VERSION_ORIG);
HttpResponse response = helper.postAddModifyApp(app);
Assert.assertTrue(response.getStatusCode() == 200);
String output = Utils.readInputStream(response.getResponseBody(), FormConstants.CHAR_ENC_DEFAULT);
Assert.assertTrue(output.contains(APP_ADDMODIFY_SUCCESS));
// Now check the database, to make sure everything got in there
Application dbApp = modelManager.getModelService().findApplicationByName(APP_NAME);
Assert.assertTrue(dbApp != null);
helper.assertSame(app, dbApp);
Assert.assertTrue(dbApp.getProxyAuthSalt() != null && dbApp.getProxyAuthSalt().length() == 36);
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class ServletManagementServletTest method testRefreshApplication.
@Test
public void testRefreshApplication() throws Exception {
MockHttpServletRequest request = new Request();
MockHttpServletResponse response = new MockHttpServletResponse();
String randomUuid = UUID.randomUUID().toString();
GlobalSettings settings = modelManager.getGlobalSettings();
/////////////////
// validate that finding the application, modifying it, and then finding it again
// will return an object with the same modifications.
Application app = modelManager.getModelService().findByPrimaryKey(Application.class, 1L);
app.setName(randomUuid);
Assert.assertTrue(modelManager.getModelService().findByPrimaryKey(Application.class, 1L).getName().equals(randomUuid));
modelManager.refresh(app, null);
app = modelManager.getModelService().findByPrimaryKey(Application.class, 1L);
Assert.assertTrue(!modelManager.getModelService().findByPrimaryKey(Application.class, 1L).getName().equals(randomUuid));
ServiceManagementServlet servlet = new ServiceManagementServlet();
servlet.setModelManager(modelManager);
servlet.setModelServiceRefreshHandler(new ModelServiceRefreshHandler());
servlet.getModelServiceRefreshHandler().setModelManager(modelManager);
////////////////////
// validate the happy path of providing all the required information
String authSalt = servlet.getAuthSalt();
String authToken = AuthTokenProvider.newAuthToken(authSalt);
request.setParameter(UrlParamConstants.REFRESH_TYPE, "Application");
request.setParameter(UrlParamConstants.REFRESH_OBJ_PKID, "1");
request.setParameter(UrlParamConstants.AUTH_TOKEN, authToken);
request.setParameter(UrlParamConstants.ACTION, ModelEntityEventAction.MODEL_REFRESH.getActionName());
servlet.service(request, response);
String contentString = response.getContentAsString();
JSONObjectBuilder job = new JSONObjectBuilder();
Result result = (Result) job.fromJSON(new JSONObject(contentString), new Result());
Assert.assertTrue(result.getStatus().equals(Result.Status.SUCCESS));
Assert.assertTrue(!modelManager.getModelService().findByPrimaryKey(Application.class, 1L).getName().equals(randomUuid));
////////////////////
// validate that failing to provide auth token fails to refresh cache
app = modelManager.getModelService().findByPrimaryKey(Application.class, 1L);
app.setName(randomUuid);
response = new MockHttpServletResponse();
request.removeParameter(UrlParamConstants.AUTH_TOKEN);
request.setParameter(UrlParamConstants.ACTION, ModelEntityEventAction.MODEL_REFRESH.getActionName());
request.setParameter(UrlParamConstants.REFRESH_TYPE, "Application");
request.setParameter(UrlParamConstants.REFRESH_OBJ_PKID, "1");
servlet.service(request, response);
contentString = response.getContentAsString();
result = (Result) job.fromJSON(new JSONObject(contentString), new Result());
Assert.assertTrue(result.getStatus().equals(Result.Status.FAILURE));
Assert.assertTrue(modelManager.getModelService().findByPrimaryKey(Application.class, 1L).getName().equals(randomUuid));
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class AdminTest method testCreateDeployments.
public void testCreateDeployments() throws Exception {
Result result = null;
ApplicationVersion version1 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_01);
ApplicationVersion version2 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_02);
UpdateHeader update = null;
_createDeployment(VERSION_01, Deployment.Type.IMMEDIATE);
modelManager.getModelService().clearPersistenceContext();
Application app = modelManager.getModelService().findApplicationByName(APP_NAME);
Assert.assertTrue(app.getDeployments().size() == 1);
result = helper.getConnectionOpen(version2, SLIC_VERSION);
update = result.getConnectionOpenResponse().getUpdate();
Assert.assertTrue(update.getType().value().equals(Deployment.Type.IMMEDIATE.name()));
Assert.assertTrue(update.getVersionIdentifier().equals(VERSION_01));
Assert.assertTrue(update.getHash().getValue().equals(VERSION_01_HASH));
Assert.assertTrue(update.getStorageNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH));
Assert.assertTrue(update.getInstallNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH + VERSION_01_BYTES_LENGTH));
_createDeployment(VERSION_02, Deployment.Type.REQUIRED);
modelManager.getModelService().clearPersistenceContext();
app = modelManager.getModelService().findApplicationByName(APP_NAME);
Assert.assertTrue(app.getDeployments().size() == 2);
result = helper.getConnectionOpen(version1, SLIC_VERSION);
update = result.getConnectionOpenResponse().getUpdate();
Assert.assertTrue(update.getType().value().equals(Deployment.Type.REQUIRED.name()));
Assert.assertTrue(update.getVersionIdentifier().equals(VERSION_02));
Assert.assertTrue(update.getHash().getValue().equals(VERSION_02_HASH));
Assert.assertTrue(update.getStorageNeeds().equals(VERSION_02_UNCOMPRESSED_BYTES_LENGTH));
Assert.assertTrue(update.getInstallNeeds().equals(VERSION_02_UNCOMPRESSED_BYTES_LENGTH + VERSION_02_BYTES_LENGTH));
_createDeployment(VERSION_02, Deployment.Type.REQUIRED);
Assert.assertTrue("as this deployment is created, the archive for version01 should be removed from the deployed location", !_isVersionArchiveInDeployedLocation(VERSION_01_HASH));
_createDeployment(VERSION_01, Deployment.Type.IMMEDIATE);
Assert.assertTrue("as this deployment is created, the archive for version01 should be in the deployed location", _isVersionArchiveInDeployedLocation(VERSION_01_HASH));
result = helper.getConnectionOpen(version2, SLIC_VERSION);
update = result.getConnectionOpenResponse().getUpdate();
Assert.assertTrue(update.getType().value().equals(Deployment.Type.IMMEDIATE.name()));
Assert.assertTrue(update.getVersionIdentifier().equals(VERSION_01));
Assert.assertTrue(update.getHash().getValue().equals(VERSION_01_HASH));
Assert.assertTrue(update.getStorageNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH));
Assert.assertTrue(update.getInstallNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH + VERSION_01_BYTES_LENGTH));
modelManager.getModelService().clearPersistenceContext();
app = modelManager.getModelService().findApplicationByName(APP_NAME);
Assert.assertTrue(app.getDeployments().size() == 2);
Assert.assertTrue(app.getDeployments().get(0).getVersionIdentifier().equals(VERSION_02));
Assert.assertTrue(app.getDeployments().get(1).getVersionIdentifier().equals(VERSION_01));
}
Aggregations