Skip to content

Commit

Permalink
EBAY-KYLIN-2589 Provide one more option to indicate whether to migrat…
Browse files Browse the repository at this point in the history
…e cube data (apache#155)

* Migrate_Cube_Withdata

* add_Email_Context

* add_Email_Context_Failed
  • Loading branch information
Ted-Jiang authored and GitHub Enterprise committed Sep 15, 2020
1 parent fcbe2b1 commit 7f6f9a7
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 19 deletions.
Expand Up @@ -104,7 +104,7 @@ public String requestMigration(@PathVariable String cubeName, @RequestBody Migra
CubeInstance cube = getCubeInstance(cubeName);
try {
MigrationRuleSet.Context ctx = new MigrationRuleSet.Context(queryService, cube,
getTargetHost(request.getTargetHost()), request.getProjectName());
getTargetHost(request.getTargetHost()), request.getProjectName(), request.getMigrateWithData());
migrationService.requestMigration(cube, ctx);
} catch (Exception e) {
logger.error("Request migration failed.", e);
Expand All @@ -128,7 +128,7 @@ public String approve(@PathVariable String cubeName, @RequestBody MigrationReque
CubeInstance cube = getCubeInstance(cubeName);
try {
MigrationRuleSet.Context ctx = new MigrationRuleSet.Context(queryService, cube,
getTargetHost(request.getTargetHost()), request.getProjectName());
getTargetHost(request.getTargetHost()), request.getProjectName(), request.getMigrateWithData());
migrationService.approve(cube, ctx);
} catch (Exception e) {
throw new BadRequestException(e.getMessage());
Expand Down
Expand Up @@ -22,6 +22,7 @@ public class MigrationRequest {
private String targetHost;
private String projectName;
private String reason; // reject reason
private String migrateWithData;

public String getTargetHost() {
return targetHost;
Expand All @@ -46,4 +47,12 @@ public String getReason() {
public void setReason(String reason) {
this.reason = reason;
}

public String getMigrateWithData() {
return migrateWithData;
}

public void setMigrateWithData(String migrateWithData) {
this.migrateWithData = migrateWithData;
}
}
Expand Up @@ -427,14 +427,21 @@ public static class Context {
private final ResourceStore targetResourceStore;
private final String tgtProjectName; // the target project name
private final ProjectInstance srcProject; // the source project
private final String migrateWithData;

public Context(QueryService queryService, CubeInstance cubeInstance, String targetHost, String tgtProjectName) {
this(queryService, cubeInstance, targetHost, tgtProjectName, "false");
}

public Context(QueryService queryService, CubeInstance cubeInstance, String targetHost, String tgtProjectName,
String migrateWithData) {
this.queryService = queryService;
this.cubeInstance = cubeInstance;
this.targetAddress = targetHost;
KylinConfig targetConfig = KylinConfig.createInstanceFromUri(targetHost);
this.targetResourceStore = ResourceStore.getStore(targetConfig);
this.tgtProjectName = tgtProjectName;
this.migrateWithData = migrateWithData;

List<ProjectInstance> projList = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv())
.findProjects(cubeInstance.getType(), cubeInstance.getName());
Expand Down Expand Up @@ -472,5 +479,9 @@ public String getSrcProjectName() {
public ProjectInstance getSrcProject() {
return srcProject;
}

public String getMigrateWithData() {
return migrateWithData;
}
}
}
Expand Up @@ -75,6 +75,8 @@ public void requestMigration(CubeInstance cube, MigrationRuleSet.Context ctx) th
root.put("cubename", ctx.getCubeInstance().getName());
root.put("status", "NEED APPROVE");
root.put("envname", envName);
root.put("migrateWithData", ctx.getMigrateWithData());

sendMigrationMail(MailNotificationUtil.MIGRATION_REQUEST, getEmailRecipients(cube), root);
}

Expand Down Expand Up @@ -104,27 +106,34 @@ public void approve(CubeInstance cube, MigrationRuleSet.Context ctx) throws Exce
String cubeName = cube.getName();
String projectName = ctx.getTgtProjectName();
try {
sendApprovedMailQuietly(cubeName, projectName);

// do cube migration
new CubeMigrationCLI().moveCube(localHost, ctx.getTargetAddress(), cubeName, projectName, "true", "false",
"true", "true", "false");
sendApprovedMailQuietly(cubeName, projectName, ctx.getMigrateWithData());

if (!ctx.getMigrateWithData().isEmpty() && "true".equalsIgnoreCase(ctx.getMigrateWithData())) {
// do cube migration with data
new CubeMigrationCLI().moveCube(localHost, ctx.getTargetAddress(), cubeName, projectName, "true",
"true", "true", "true", "true");
} else {
// do cube migration withOut data
new CubeMigrationCLI().moveCube(localHost, ctx.getTargetAddress(), cubeName, projectName, "true",
"false", "true", "true", "false");
}

sendCompletedMailQuietly(cubeName, projectName);
sendCompletedMailQuietly(cubeName, projectName, ctx.getMigrateWithData());
} catch (Exception e) {
logger.error(e.getMessage(), e);
sendMigrationFailedMailQuietly(cubeName, projectName, e.getMessage());
sendMigrationFailedMailQuietly(cubeName, projectName, e.getMessage(), ctx.getMigrateWithData());
throw e;
}
}

private boolean sendApprovedMailQuietly(String cubeName, String projectName) {
private boolean sendApprovedMailQuietly(String cubeName, String projectName, String migrateWithData) {
try {
Map<String, String> root = Maps.newHashMap();
root.put("projectname", projectName);
root.put("cubename", cubeName);
root.put("status", "APPROVED");
root.put("envname", envName);
root.put("migrateWithData", migrateWithData);

sendMigrationMail(MailNotificationUtil.MIGRATION_APPROVED, getEmailRecipients(cubeName), root);
} catch (Exception e) {
Expand All @@ -134,13 +143,14 @@ private boolean sendApprovedMailQuietly(String cubeName, String projectName) {
return true;
}

private boolean sendCompletedMailQuietly(String cubeName, String projectName) {
private boolean sendCompletedMailQuietly(String cubeName, String projectName, String migrateWithData) {
try {
Map<String, String> root = Maps.newHashMap();
root.put("projectname", projectName);
root.put("cubename", cubeName);
root.put("status", "COMPLETED");
root.put("envname", envName);
root.put("migrateWithData", migrateWithData);

sendMigrationMail(MailNotificationUtil.MIGRATION_COMPLETED, getEmailRecipients(cubeName), root);
} catch (Exception e) {
Expand All @@ -150,14 +160,16 @@ private boolean sendCompletedMailQuietly(String cubeName, String projectName) {
return true;
}

private boolean sendMigrationFailedMailQuietly(String cubeName, String projectName, String reason) {
private boolean sendMigrationFailedMailQuietly(String cubeName, String projectName, String reason,
String migrateWithData) {
try {
Map<String, String> root = Maps.newHashMap();
root.put("projectname", projectName);
root.put("cubename", cubeName);
root.put("status", "FAILED");
root.put("failedReason", reason);
root.put("envname", envName);
root.put("migrateWithData", migrateWithData);

sendMigrationMail(MailNotificationUtil.MIGRATION_FAILED, getEmailRecipients(cubeName), root);
} catch (Exception e) {
Expand Down
Expand Up @@ -163,6 +163,29 @@ border-left:0px;">
${cubename}</h4>
</td>
</tr>
<tr>
<th width="30%" style="border: 1px solid #ddd;
padding: 8px;">
<h4 style="
margin-top: 0;
margin-bottom: 0;
line-height: 1.5;
text-align: left;
font-size: 14px;
font-style: normal;">Migrate With Data</h4>
</th>
<td style="border: 1px solid #ddd;
padding: 8px;">
<h4 style="margin-top: 0;
margin-bottom: 0;
line-height: 1.5;
text-align: left;
font-size: 14px;
font-style: normal;
font-weight: 300;">
${migrateWithData}</h4>
</td>
</tr>
</table>
</td>
</tr>
Expand Down
Expand Up @@ -162,6 +162,29 @@ border-left:0px;">
font-weight: 300;">${cubename}</h4>
</td>
</tr>
<tr>
<th width="30%" style="border: 1px solid #ddd;
padding: 8px;">
<h4 style="
margin-top: 0;
margin-bottom: 0;
line-height: 1.5;
text-align: left;
font-size: 14px;
font-style: normal;">Migrate With Data</h4>
</th>
<td style="border: 1px solid #ddd;
padding: 8px;">
<h4 style="margin-top: 0;
margin-bottom: 0;
line-height: 1.5;
text-align: left;
font-size: 14px;
font-style: normal;
font-weight: 300;">
${migrateWithData}</h4>
</td>
</tr>
</table>
</td>
</tr>
Expand Down
Expand Up @@ -190,6 +190,29 @@ border-left:0px;">
${failedReason}</h4>
</td>
</tr>
<tr>
<th width="30%" style="border: 1px solid #ddd;
padding: 8px;">
<h4 style="
margin-top: 0;
margin-bottom: 0;
line-height: 1.5;
text-align: left;
font-size: 14px;
font-style: normal;">Migrate With Data</h4>
</th>
<td style="border: 1px solid #ddd;
padding: 8px;">
<h4 style="margin-top: 0;
margin-bottom: 0;
line-height: 1.5;
text-align: left;
font-size: 14px;
font-style: normal;
font-weight: 300;">
${migrateWithData}</h4>
</td>
</tr>
</table>
</td>
</tr>
Expand Down
Expand Up @@ -165,7 +165,29 @@ border-left:0px;">
${cubename}</h4>
</td>
</tr>

<tr>
<th width="30%" style="border: 1px solid #ddd;
padding: 8px;">
<h4 style="
margin-top: 0;
margin-bottom: 0;
line-height: 1.5;
text-align: left;
font-size: 14px;
font-style: normal;">Migrate With Data</h4>
</th>
<td style="border: 1px solid #ddd;
padding: 8px;">
<h4 style="margin-top: 0;
margin-bottom: 0;
line-height: 1.5;
text-align: left;
font-size: 14px;
font-style: normal;
font-weight: 300;">
${migrateWithData}</h4>
</td>
</tr>
</table>
</td>
</tr>
Expand Down
6 changes: 4 additions & 2 deletions webapp/app/js/controllers/cubes.js
Expand Up @@ -1204,7 +1204,8 @@ var cubeMigrateCtrl = function ($scope, $modalInstance, CubeService, cube, Proje
}

$scope.MigrationRequest = {
projectName:$scope.migrate.targetProject
projectName:$scope.migrate.targetProject,
migrateWithData:$scope.migrate.migrateWithData
}

SweetAlert.swal({
Expand Down Expand Up @@ -1241,7 +1242,8 @@ var cubeMigrateCtrl = function ($scope, $modalInstance, CubeService, cube, Proje

$scope.migrateApprove = function(){
$scope.MigrationRequest = {
projectName:$scope.migrate.targetProject
projectName:$scope.migrate.targetProject,
migrateWithData:$scope.migrate.migrateWithData
}
loadingRequest.show();
CubeService.approve({cubeId: cube.name}, $scope.MigrationRequest, function (result) {
Expand Down
20 changes: 16 additions & 4 deletions webapp/app/partials/cubes/cube_migrate.html
Expand Up @@ -24,10 +24,15 @@ <h4 tooltip="submit">MIGRATE CUBE</h4>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="form-group">
<b>Target Project Name:</b>
<br/>
<p style="color:red;font-size:12px;">You can change the below project name if it's different on Kylin Prod.</p>
<b>Target Project Name: </b>
<input type="text" class="form-control" ng-readonly="migrate.lockProjectName" ng-model="migrate.targetProject" />
<p style="color:red;font-size:12px;">You can change the below project name if it's different on Kylin Prod.</p>
<br/>
<div>
<b>Migrate With Data: </b>
<input type="checkbox" ng-model="migrate.migrateWithData" value="true" defaultValue = "false"/>
<p style="color:red;font-size:12px;">You can choose whether to migrate with data .</p>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -65,9 +70,16 @@ <h4 tooltip="submit">MIGRATE APPROVE</h4>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="form-group">
<div>
<b>Target Project Name:</b>
<br/>
<input type="text" class="form-control" ng-model="migrate.targetProject" value={{migrate.targetProject}}/>
</div>
<br/>
<div>
<p style="color:red;font-size:12px;">You can choose whether to migrate with data .</p>
<b>Migrate With Data: </b>
<input type="checkbox" ng-model="migrate.migrateWithData" value="true" defaultValue = "false"/>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 7f6f9a7

Please sign in to comment.