Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Feb 20, 2023
1 parent 4ef4aba commit 9d9c672
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
FlowValidateCommand.class,
FlowTestCommand.class,
FlowNamespaceCommand.class,
FlowDotCommand.class
FlowDotCommand.class,
FlowExportCommand.class,
}
)
@Slf4j
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.kestra.cli.commands.flows.namespaces;
package io.kestra.cli.commands.flows;

import io.kestra.cli.AbstractApiCommand;
import io.kestra.cli.commands.flows.FlowValidateCommand;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
Expand All @@ -16,17 +15,17 @@

@CommandLine.Command(
name = "export",
description = "export namespace flows",
description = "export flows to a zip file",
mixinStandardHelpOptions = true
)
@Slf4j
public class FlowNamespaceExportCommand extends AbstractApiCommand {
public class FlowExportCommand extends AbstractApiCommand {
private static final String DEFAULT_FILE_NAME = "flows.zip";

@CommandLine.Parameters(index = "0", description = "the namespace of templates to export")
@CommandLine.Option(names = {"--namespace"}, description = "the namespace of flows to export")
public String namespace;

@CommandLine.Parameters(index = "1", description = "the directory to export the file to")
@CommandLine.Parameters(index = "0", description = "the directory to export the file to")
public Path directory;

@Override
Expand All @@ -35,7 +34,8 @@ public Integer call() throws Exception {

try(DefaultHttpClient client = client()) {
MutableHttpRequest<Object> request = HttpRequest
.GET("/api/v1/flows/export/by-query?namespace=" + namespace).accept(MediaType.APPLICATION_OCTET_STREAM);
.GET("/api/v1/flows/export/by-query" + (namespace != null ? "?namespace=" + namespace : ""))
.accept(MediaType.APPLICATION_OCTET_STREAM);

HttpResponse<byte[]> response = client.toBlocking().exchange(this.requestOptions(request), byte[].class);
Path zipFile = Path.of(directory.toString(), DEFAULT_FILE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
mixinStandardHelpOptions = true,
subcommands = {
TemplateNamespaceCommand.class,
TemplateValidateCommand.class
TemplateValidateCommand.class,
TemplateExportCommand.class,
}
)
@Slf4j
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.kestra.cli.commands.templates.namespaces;
package io.kestra.cli.commands.templates;

import io.kestra.cli.AbstractApiCommand;
import io.kestra.cli.commands.templates.TemplateValidateCommand;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
Expand All @@ -16,17 +15,17 @@

@CommandLine.Command(
name = "export",
description = "export namespace templates",
description = "export templates to a zip file",
mixinStandardHelpOptions = true
)
@Slf4j
public class TemplateNamespaceExportCommand extends AbstractApiCommand {
public class TemplateExportCommand extends AbstractApiCommand {
private static final String DEFAULT_FILE_NAME = "templates.zip";

@CommandLine.Parameters(index = "0", description = "the namespace of templates to export")
@CommandLine.Option(names = {"--namespace"}, description = "the namespace of templates to export")
public String namespace;

@CommandLine.Parameters(index = "1", description = "the directory to export the file to")
@CommandLine.Parameters(index = "0", description = "the directory to export the file to")
public Path directory;

@Override
Expand All @@ -35,7 +34,8 @@ public Integer call() throws Exception {

try(DefaultHttpClient client = client()) {
MutableHttpRequest<Object> request = HttpRequest
.GET("/api/v1/templates/export/by-query?namespace=" + namespace).accept(MediaType.APPLICATION_OCTET_STREAM);
.GET("/api/v1/templates/export/by-query" + (namespace != null ? "?namespace=" + namespace : ""))
.accept(MediaType.APPLICATION_OCTET_STREAM);

HttpResponse<byte[]> response = client.toBlocking().exchange(this.requestOptions(request), byte[].class);
Path zipFile = Path.of(directory.toString(), DEFAULT_FILE_NAME);
Expand All @@ -50,5 +50,4 @@ public Integer call() throws Exception {

return 0;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kestra.cli.commands.flows.namespaces;
package io.kestra.cli.commands.flows;

import io.kestra.cli.commands.flows.namespaces.FlowNamespaceUpdateCommand;
import io.micronaut.configuration.picocli.PicocliRunner;
import io.micronaut.context.ApplicationContext;
import io.micronaut.context.env.Environment;
Expand All @@ -17,15 +18,14 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.StringContains.containsString;

class FlowNamespaceExportCommandTest {
class FlowExportCommandTest {
@Test
void run() throws IOException {
URL directory = FlowNamespaceUpdateCommandTest.class.getClassLoader().getResource("flows");
URL directory = FlowExportCommandTest.class.getClassLoader().getResource("flows");
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

try (ApplicationContext ctx = ApplicationContext.run(Environment.CLI, Environment.TEST)) {

EmbeddedServer embeddedServer = ctx.getBean(EmbeddedServer.class);
embeddedServer.start();

Expand All @@ -37,7 +37,6 @@ void run() throws IOException {
"myuser:pass:word",
"io.kestra.cli",
directory.getPath(),

};
PicocliRunner.call(FlowNamespaceUpdateCommand.class, ctx, updateArgs);
assertThat(out.toString(), containsString("3 flow(s)"));
Expand All @@ -48,10 +47,11 @@ void run() throws IOException {
embeddedServer.getURL().toString(),
"--user",
"myuser:pass:word",
"--namespace",
"io.kestra.cli",
"/tmp",
};
PicocliRunner.call(FlowNamespaceExportCommand.class, ctx, exportArgs);
PicocliRunner.call(FlowExportCommand.class, ctx, exportArgs);
File file = new File("/tmp/flows.zip");
assertThat(file.exists(), is(true));
ZipFile zipFile = new ZipFile(file);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kestra.cli.commands.templates.namespaces;
package io.kestra.cli.commands.templates;

import io.kestra.cli.commands.templates.namespaces.TemplateNamespaceUpdateCommand;
import io.micronaut.configuration.picocli.PicocliRunner;
import io.micronaut.context.ApplicationContext;
import io.micronaut.context.env.Environment;
Expand All @@ -17,10 +18,10 @@
import static org.hamcrest.core.StringContains.containsString;
import static org.hamcrest.core.Is.is;

class TemplateNamespaceExportCommandTest {
class TemplateExportCommandTest {
@Test
void run() throws IOException {
URL directory = TemplateNamespaceExportCommandTest.class.getClassLoader().getResource("templates");
URL directory = TemplateExportCommandTest.class.getClassLoader().getResource("templates");
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

Expand Down Expand Up @@ -48,10 +49,11 @@ void run() throws IOException {
embeddedServer.getURL().toString(),
"--user",
"myuser:pass:word",
"--namespace",
"io.kestra.tests",
"/tmp",
};
PicocliRunner.call(TemplateNamespaceExportCommand.class, ctx, exportArgs);
PicocliRunner.call(TemplateExportCommand.class, ctx, exportArgs);
File file = new File("/tmp/templates.zip");
assertThat(file.exists(), is(true));
ZipFile zipFile = new ZipFile(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
@ToString
@EqualsAndHashCode
public class Template implements DeletedInterface {

private static final ObjectMapper YAML_MAPPER = JacksonMapper.ofYaml().copy()
.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
@Override
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/flows/Flows.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<bottom-line-counter v-model="queryBulkAction" :selections="flowsSelection" :total="total" @update:model-value="selectAll()" />
<li v-if="canRead">
<el-button :icon="Download" type="info" class="bulk-button" @click="exportFlows()">
{{ $t('exports') }}
{{ $t('export') }}
</el-button>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/templates/Templates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<bottom-line-counter v-model="queryBulkAction" :selections="templatesSelection" :total="total" @update:model-value="selectAll()" />
<li v-if="canRead">
<el-button :icon="Download" type="info" class="bulk-button" @click="exportTemplates()">
{{ $t('exports') }}
{{ $t('export') }}
</el-button>
</li>
</ul>
Expand Down
29 changes: 15 additions & 14 deletions ui/src/stores/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,22 @@ export default {
validateStatus: (status) => {
return options.deleted ? status === 200 || status === 404 : status === 200;
}
}).then(response => {
if (response.data.exception) {
commit("core/setMessage", {
title: "Invalid source code",
message: response.data.exception,
variant: "danger"
}, {root: true});
delete response.data.exception;
commit("setFlow", JSON.parse(response.data.source));
} else {
commit("setFlow", response.data);
}
})
.then(response => {
if (response.data.exception) {
commit("core/setMessage", {
title: "Invalid source code",
message: response.data.exception,
variant: "danger"
}, {root: true});
delete response.data.exception;
commit("setFlow", JSON.parse(response.data.source));
} else {
commit("setFlow", response.data);
}

return response.data;
})
return response.data;
})
},
loadTask({commit}, options) {
return this.$http.get(`/api/v1/flows/${options.namespace}/${options.id}/tasks/${options.taskId}${options.revision ? "?revision=" + options.revision : ""}`).then(response => {
Expand Down
11 changes: 7 additions & 4 deletions ui/src/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
"execution not in state FAILED": "Execution <code>{executionId}</code> not in state FAILED",
"execution already finished": "Execution <code>{executionId}</code> already finished",
"seeing old revision": "You are seeing an old revision: {revision}",
"export": "Export",
"template export": "Are you sure you want to export <code>{templateCount}</code> template(s)?",
"templates exported": "Templates exported",
"flow export": "Are you sure you want to export <code>{flowCount}</code> flow(s)?",
Expand Down Expand Up @@ -549,6 +550,7 @@
"execution already finished": "Execution <code>{executionId}</code> déjà terminée",
"restore revision": "Êtes-vous sur de vouloir restaurer la revision <code>{revision}</code> ?",
"seeing old revision": "Vous visualisez une ancienne revision : {revision}",
"export": "Exporter",
"template export": "Êtes vous sûr de vouloir exporter <code>{templateCount}</code> template(s)?",
"templates exported": "Templates exportés",
"flow export": "Êtes vous sûr de vouloir exporter <code>{flowCount}</code> flow(s)?",
Expand Down Expand Up @@ -826,9 +828,10 @@
"execution not in state FAILED": "Ausführung <code>{executionId}</code> nicht im Status FAILED",
"execution already finished": "Ausführung <code>{executionId}</code> bereits abgeschlossen",
"seeing old revision": "Sie sehen eine alte Revision: {revision}",
"template export": "Are you sure you want to export <code>{templateCount}</code> template(s)?",
"templates exported": "Templates exported",
"flow export": "Are you sure you want to export <code>{flowCount}</code> flow(s)?",
"flows exported": "Flows exported"
"export": "Export",
"template export": "Sind Sie sicher, dass Sie <code>{templateCount}</code> Template(n) exportieren möchten?",
"templates exported": "Template exportiert",
"flow export": "Sind Sie sicher, dass Sie <code>{flowCount}</code> Flows exportieren möchten?",
"flows exported": "Flows exportiert"
}
}
1 change: 0 additions & 1 deletion ui/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,4 @@ export default class Utils {
document.body.appendChild(link);
link.click();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ public HttpResponse<byte[]> exportByQuery(
) throws IOException {
var flows = flowRepository.findWithSource(query, namespace, RequestUtils.toMap(labels));
var bytes = zipFlows(flows);

return HttpResponse.ok(bytes).header("Content-Disposition", "attachment; filename=\"flows.zip\"");
}

Expand All @@ -452,7 +453,7 @@ public HttpResponse<byte[]> exportByIds(
return HttpResponse.ok(bytes).header("Content-Disposition", "attachment; filename=\"flows.zip\"");
}

private byte[] zipFlows(List<FlowWithSource> flows) throws IOException {
private static byte[] zipFlows(List<FlowWithSource> flows) throws IOException {
try(ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream archive = new ZipOutputStream(bos)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public HttpResponse<byte[]> exportByIds(
return HttpResponse.ok(bytes).header("Content-Disposition", "attachment; filename=\"templates.zip\"");
}

private byte[] zipTemplates(List<Template> templates) throws IOException {
private static byte[] zipTemplates(List<Template> templates) throws IOException {
try(ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream archive = new ZipOutputStream(bos)) {

Expand Down

0 comments on commit 9d9c672

Please sign in to comment.