Skip to content

Refactoring UmpleOnline's storage backend

Finn Hackett edited this page Nov 29, 2017 · 4 revisions

Principal idea

Based on interpreting all the string manipulations it currently uses, it seems all UmpleOnline really needs to do is:

  • Create an anonymous storage location (atomic operation, also acquires lock)
  • Create a named storage location (atomic operation, also acquires lock)
  • Acquire an exclusive lock on a named storage location, and:
    • Query its fields
    • Delete it
    • Clone it
  • Acquire a working directory containing resources from a storage location in which commands may be run
  • Create permalinks to generated content (note: does not have to be links to the UmpleOnline server, but is at the moment)

My plan at this point was to create an API that does this and reimplement the existing functionality with it, removing all the assumptions embedded in the existing code as I go as well as adding concurrency-safety.

Files touched

  • scripts/compiler_config.php
  • scripts/compiler.php
  • scripts/compiler_vml.php
  • scripts/simulate_config.php
  • simulate.php
  • bookmark.php
  • umple.php

Lines of interest


umple.php:  if (!is_file("ump/".$_REQUEST["model"]."/model.ump")) {
umple.php:$output = readTemporaryFile("ump/" . $filename);

bookmark.php:$savedModel = nextFilename("ump",date("ymd"));
bookmark.php:$filename = "ump/{$tempModelId}/model.ump";
bookmark.php:    recursiveDelete("ump/{$tempModelId}");
bookmark.php:  recursiveDelete("ump/{$saveModelId}");
bookmark.php:if (!is_file("ump/{$tempModelId}/model.ump.erroroutput"))
bookmark.php:    recursiveDelete("ump/{$tempModelId}");
bookmark.php:  recursiveDelete("ump/{$saveModelId}");

scripts/compiler_vml.php:  $filename = "../ump/" . $_REQUEST["exampleCode"];

scripts/simulate_config.php:    require_once "ump/{$modelId}/{$class_name}.php";

-- note: not sure about these, requires review --
scripts/compiler.php:	if (file_exists("JSFProvider/model.ump"))
scripts/compiler.php:	  unlink("JSFProvider/model.ump");
scripts/compiler.php:    copy("$filename", "JSFProvider/model.ump");
scripts/compiler.php:       $theurldir = "ump/" . basename($thedir);

-- note: these are indirect, in reality you want to fix $thedir but if you want flexibility on your permalinks
-- it is unhelpful to assume they will be on the same server (see note above)
scripts/compiler.php:       $html = "<a href=\"umpleonline/$thedir/\">Download the following as a zip file</a>&nbsp;{$errhtml}
scripts/compiler.php:      $html = "<a href=\"umpleonline/$thedir/model.gv\">Download the GraphViz file for the following</a>&nbsp;<a href=\"umpleonline/$thedir/stateDiagram.svg\">Download the SVG file for the following</a>&nbsp;<br/>{$errhtml}&nbsp;
scripts/compiler.php:      $html = "<a href=\"umpleonline/$thedir/model" . $generatorType . ".gv\">Download the GraphViz file for the following</a>&nbsp;<a href=\"umpleonline/$thedir/classDiagram.svg\">Download the SVG file for the following</a>&nbsp;<br/>{$errhtml}&nbsp;
scripts/compiler.php:      $html = "<a href=\"umpleonline/$thedir/modelerd.gv\">Download the GraphViz file for the following</a>&nbsp;<a href=\"umpleonline/$thedir/entityRelationshipDiagram.svg\">Download the SVG file for the following</a>&nbsp;<br/>{$errhtml}&nbsp;
scripts/compiler.php:      $command = "cp " . $thedir . "/model.ump.output " . $thedir .  "/yuml.txt";
scripts/compiler.php:      $html = "<a href=\"umpleonline/$thedir/yuml.txt\">Download the Yuml text for the following</a>&nbsp;{$errhtml}";
scripts/compiler.php:	   echo "<a href=\"umpleonline/$thedir/{$language}\" class=\"zipDownloadLink\">Download the following as a zip file</a>&nbsp;{$errhtml}<p>URL_SPLIT";
scripts/compiler.php:	$html = "<a href=\"$theurldir/umpleUIGU.war\">Download the generated application as web archive (WAR) file.</a>&nbsp;{$errhtml}

-- everything below this point falls under the general issue of "using relative paths", some of it
-- relies on the working directory being in a specific place, see (1). generally, needs proper analysis

scripts/compiler.php:	$theurldir = "ump/" . basename($thedir);
scripts/compiler.php:  $filename = "../ump/" . $_REQUEST["exampleCode"];

scripts/compiler_config.php:    $index = strpos($filename,"/model.ump");
scripts/compiler_config.php:  $file_suffix = explode("/umpleonline/", realpath(""));
scripts/compiler_config.php:    $filename = "../ump/". $_REQUEST["model"] ."/model.ump";
scripts/compiler_config.php:    if (!file_exists("ump/" . $filename)) {
scripts/compiler_config.php:      $destfile = nextFilename("ump");
scripts/compiler_config.php:      if (file_exists("ump/" . $_REQUEST["model"] ."/readonlylock.txt"))
scripts/compiler_config.php:          $fileToCopy = "ump/" . $filename;
scripts/compiler_config.php:          $destfile = nextFilename("ump");
scripts/compiler_config.php:    $fileToCopy = "ump/".htmlspecialchars($_REQUEST['example']).".ump";
scripts/compiler_config.php:    $destfile = nextFilename("ump");
scripts/compiler_config.php:    $destfile = nextFilename("ump");
scripts/compiler_config.php:    $filename = "../" . nextFilename("ump");
scripts/compiler_config.php:    $destfile = nextFilename("ump");
scripts/compiler_config.php:    if(!substr($_REQUEST["filename"],-4)==".ump") {
scripts/compiler_config.php:       file_put_contents($destfile, "// URL in filename argument must end in .ump and the initial http:// must be omitted");
scripts/compiler_config.php:          file_put_contents($destfile, "// URL of the Umple file to be loaded in the URL after ?filename= must omit the initial http:// and end with .ump.\n// The file must be accessible from our server.\n// Could not load http://" . $_REQUEST["filename"]);
scripts/compiler_config.php:  return substr($filename,7,strlen($filename) - strlen("../ump/") - strlen("/model.ump"));
scripts/compiler_config.php:function nextFilename($basedir = "../ump", $prefix = "tmp")
scripts/compiler_config.php:    $filename = "{$dirname}/model.ump";
scripts/compiler_config.php:	$umpDir=dirname($tempDir);

-- (1)
scripts/compiler_config.php:	$output = executeCommand("ant -DxmlFile=../../scripts/JSFProvider/UmpleProject.xml -DumpleFile=model.ump -DoutputFolder=TempApp -DprojectName=umpleUIGU");

scripts/compiler_config.php:		copy("umpleUIGU.war", "TempProj/umpleUIGU.war");
scripts/compiler_config.php:		executeCommand("jar xf umpleUIGU.war");
scripts/compiler_config.php:		unlink('umpleUIGU.war');
scripts/compiler_config.php:		$umpDir=dirname($tempDir);
scripts/compiler_config.php:		rcopy($tmp."/TempProj", $umpDir."/uigu/".$uiguDir);
scripts/compiler_config.php:  $umpleOutput = executeCommand("java -jar umplesync.jar -{$action} \"{$actionCode}\" {$filename}", "-{$action} \"{$rawActionCode}\" {$filename}");
scripts/compiler_config.php:  saveFile($umpleOutput,$filename);
scripts/compiler_config.php:  if(substr($command,0,23) == "java -jar umplesync.jar" && $useServerIfPossble) {
scripts/compiler_config.php:    execRun("java -jar umplesync.jar ".$originalCommandLine);
scripts/compiler_config.php:    execRun("java -jar umplesync.jar ".$originalCommandLine);

scripts/compiler_config.php:    exec("java -jar umplesync.jar -server ".$portnumber." > /dev/null 2>&1 &"); // Start the server for the next time

scripts/compiler_config.php:  $startOfModelFile = strpos($originalCommandLine, "../ump/");
scripts/compiler_config.php:    $endOfModelFile = strpos($originalCommandLine,"/model.ump");
scripts/compiler_config.php:  $crashLogFile = "../ump/ATempCrashCheck-".uniqid().".ump";
scripts/compiler_config.php:    execRun("java -jar umplesync.jar ".$originalCommandLine);
scripts/compiler_config.php:      execRun("nice -10 java -jar umplesync.jar ".$originalCommandLine);
scripts/compiler_config.php:    executeCommand("scripts/cleanumpinbackground");
scripts/compiler_config.php:  //  executeCommand("find ./ump -maxdepth 1 -type d -mtime +30 | grep -v .svn | grep /tmp | xargs rm -rf");
scripts/compiler_config.php:  //executeCommand("find ./ump -maxdepth 1 -type d -empty -mtime +2 | grep -v .svn |  xargs rm -rf");

-- note: what is uigu doing here? I need to look at this more carefully.
scripts/TempProj/uigudirectories.php:  // copy this file into the umpleonline/ump/uigu directory
Clone this wiki locally