Skip to content

Commit e2846cb

Browse files
authored
First pass on 2.x flow upgrade to 3, and removing unneeded modules (#938)
1 parent bfe5eac commit e2846cb

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

marklogic-data-hub/src/main/java/com/marklogic/hub/impl/DataHubImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ private Map<Integer, String> getServerPortsInUse() {
506506
}
507507

508508
//DataHubUpgrader stuff
509-
public static String MIN_UPGRADE_VERSION = "1.1.3";
509+
public static String MIN_UPGRADE_VERSION = "2.0.0";
510510

511511
@Override public boolean upgradeHub() throws CantUpgradeException {
512512
return upgradeHub(null);
@@ -545,6 +545,8 @@ private Map<Integer, String> getServerPortsInUse() {
545545
updatedFlows.addAll(flows);
546546
}
547547

548+
runInDatabase("for $i in cts:uris(\"\", (), cts:and-not-query(cts:collection-query(\"hub-core-module\"), cts:document-query((\"/com.marklogic.hub/config.sjs\", \"/com.marklogic.hub/config.xqy\")))) return xdmp:document-delete($i)", hubConfig.getDbName(DatabaseKind.MODULES));
549+
548550
if (isHubInstalled) {
549551
// install hub modules into MarkLogic
550552
this.install();

marklogic-data-hub/src/main/java/com/marklogic/hub/scaffold/impl/ScaffoldingImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ public boolean update2xFlow(String entityName, String flowName, FlowType flowTyp
280280

281281
Path flowDir = getFlowDir(entityName, flowName, flowType);
282282
Path mainPath = flowDir.resolve("main.sjs");
283+
Path xqyMainPath = flowDir.resolve("main.xqy");
283284
if (mainPath.toFile().exists()) {
284285
try {
285286
String mainFile = FileUtils.readFileToString(mainPath.toFile());
@@ -309,6 +310,22 @@ public boolean update2xFlow(String entityName, String flowName, FlowType flowTyp
309310
throw new RuntimeException(e);
310311
}
311312
}
313+
314+
if (mainPath.toFile().exists() || xqyMainPath.toFile().exists()) {
315+
if (xqyMainPath.toFile().exists()) {
316+
mainPath = xqyMainPath;
317+
}
318+
try {
319+
String mainFile = FileUtils.readFileToString(mainPath.toFile());
320+
mainFile = mainFile.replaceFirst("com\\.marklogic\\.hub", "MarkLogic/data-hub-framework");
321+
FileOutputStream fileOutputStream = new FileOutputStream(mainPath.toFile());
322+
IOUtils.write(mainFile, fileOutputStream);
323+
fileOutputStream.close();
324+
} catch (Exception e) {
325+
throw new RuntimeException(e);
326+
}
327+
}
328+
312329
return updated;
313330
}
314331

quick-start/src/main/java/com/marklogic/quickstart/web/CurrentProjectController.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,14 @@ public ResponseEntity<?> clearDatabase() {
204204

205205
@RequestMapping(value = "/update-hub", method = RequestMethod.POST)
206206
public ResponseEntity<?> updateHub() throws IOException, CantUpgradeException {
207-
if (dataHubService.updateHub(envConfig().getMlSettings())) {
208-
installUserModules(envConfig().getMlSettings(), true);
209-
startProjectWatcher();
210-
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
207+
try {
208+
if (dataHubService.updateHub(envConfig().getMlSettings())) {
209+
installUserModules(envConfig().getMlSettings(), true);
210+
startProjectWatcher();
211+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
212+
}
213+
} catch (CantUpgradeException e) {
214+
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
211215
}
212216
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
213217
}

quick-start/src/main/ui/app/login/login.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ <h3 *ngIf="currentEnvironment">Congratulations on updating to version<br>{{curre
241241
<h3>Automatic Hub Update Failed!</h3>
242242
<p *ngIf="currentEnvironment" class="error">
243243
Sorry. We failed to update you to version <span class="version">{{currentEnvironment.runningVersion}}</span>.
244+
<span>{{hubUpdateError}}.</span>
244245
</p>
245246
<p>Go read the wiki page that describes the changes necessary and try them manually.</p>
246247
<a target="_blank" [href]="hubUpdateUrl()">How to update a Hub Project</a>

quick-start/src/main/ui/app/login/login.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class LoginComponent implements OnInit {
2626
hubVersions: any;
2727
hubUpdating: boolean = false;
2828
hubUpdateFailed: boolean = false;
29+
hubUpdateError: string = '';
2930

3031
currentTab: string = 'ProjectDir';
3132

@@ -314,11 +315,13 @@ export class LoginComponent implements OnInit {
314315
this.hubUpdating = true;
315316
this.projectService.updateProject().subscribe(() => {
316317
this.hubUpdating = false;
318+
this.hubUpdateError = '';
317319
this.loginNext();
318320
},
319-
() => {
321+
error => {
320322
this.hubUpdating = false;
321323
this.hubUpdateFailed = true;
324+
this.hubUpdateError = error.json().message;
322325
});
323326
}
324327

0 commit comments

Comments
 (0)