Skip to content

Commit 3087db1

Browse files
author
rathnapandi
committed
Support deploying fed directory
1 parent a03fc9f commit 3087db1

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ java -jar apim-deployment-project/gateway-standalone/target/gateway-standalone-1
7979
java -jar apim-deployment-project/gateway-standalone/target/gateway-standalone-1.0.0.jar --operation=deploy --gatewayURL=https://localhost:8090 --username=admin --password=changeme --group=Finance --instance=server1 --fedFile=/home/axway/finance.fed --type=fed
8080
```
8181

82+
### Deploy a FED directory to a specific Gateway
83+
84+
```bash
85+
java -jar apim-deployment-project/gateway-standalone/target/gateway-standalone-1.0.0.jar --operation=deploy --gatewayURL=https://localhost:8090 --username=admin --password=changeme --group=Finance --instance=server1 --fedDir=/home/axway/finance --type=fed
86+
87+
```
88+
8289
### Deploy the POL and ENV files to all Gateways
8390

8491

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.axway.apim;
2+
3+
import java.io.*;
4+
import java.util.jar.Attributes;
5+
import java.util.jar.JarEntry;
6+
import java.util.jar.JarOutputStream;
7+
import java.util.jar.Manifest;
8+
9+
public class Archive {
10+
11+
public Manifest createManifest(String uuidStr){
12+
Manifest manifest = new Manifest();
13+
Attributes attributes = manifest.getMainAttributes();
14+
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
15+
attributes.put(new Attributes.Name("Id"),uuidStr);
16+
attributes.put(new Attributes.Name("Timestamp"), System.currentTimeMillis()+"");
17+
return manifest;
18+
}
19+
20+
public void createFed(String uuisStr, Manifest manifest, String filename, File dir) throws IOException {
21+
try (FileOutputStream fileOutputStream = new FileOutputStream(filename);
22+
JarOutputStream jarOutputStream = new JarOutputStream(fileOutputStream, manifest)){
23+
File[] files = dir.listFiles();
24+
for (File file : files) {
25+
if (!file.isDirectory()) {
26+
addContent(jarOutputStream, file, uuisStr);
27+
} else {
28+
if (file.getName().equals("meta-inf")) {
29+
File[] metaInfFiles = file.listFiles();
30+
for (File metaInfFile : metaInfFiles) {
31+
if (metaInfFile.getName().equals("manifest.mf")) {
32+
continue;
33+
}
34+
35+
addContent(jarOutputStream, metaInfFile, "meta-inf");
36+
}
37+
}
38+
}
39+
}
40+
41+
}
42+
}
43+
44+
45+
private void addContent(JarOutputStream jarOutputStream, File file, String dirName) throws IOException {
46+
try ( BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))){
47+
jarOutputStream.putNextEntry(new JarEntry(dirName + "/" + file.getName()));
48+
byte[] buffer = new byte[1024];
49+
while (true) {
50+
int count = bufferedInputStream.read(buffer);
51+
if (count == -1)
52+
break;
53+
jarOutputStream.write(buffer, 0, count);
54+
}
55+
jarOutputStream.closeEntry();
56+
}
57+
}
58+
}

apim-deployment-project/gateway-standalone/src/main/java/com/axway/apim/Main.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static void main(String[] args) {
3535
boolean inSecure = line.hasOption("insecure");
3636

3737
String fedFileName = null;
38+
String fedDir = null;
3839
String polFileName = null;
3940
String envFileName = null;
4041
String instanceName = null;
@@ -46,7 +47,9 @@ public static void main(String[] args) {
4647
if (type.equalsIgnoreCase("fed")) {
4748
if (line.hasOption('f')) {
4849
fedFileName = line.getOptionValue("f");
49-
} else {
50+
} else if(line.hasOption('d')){
51+
fedDir = line.getOptionValue("d");
52+
}else {
5053
LOGGER.error("Provide fed location");
5154
System.exit(1);
5255
}
@@ -78,7 +81,7 @@ public static void main(String[] args) {
7881
envFileName, inSecure);
7982
} else if (operation.equalsIgnoreCase("deploy")) {
8083
orchestrator.deploy(url, username, password, groupName, instanceName, type, fedFileName, polFileName,
81-
envFileName, inSecure);
84+
envFileName, inSecure, fedDir);
8285
} else {
8386
LOGGER.error("Provide valid operation name: possible values download or deploy");
8487
System.exit(1);
@@ -124,6 +127,9 @@ private static Options options() {
124127
Option fedFile = Option.builder("f").longOpt("fedFile").required(false).hasArg(true).desc("Federation File")
125128
.build();
126129

130+
Option fedDir = Option.builder("d").longOpt("fedDir").required(false).hasArg(true).desc("Federation directory")
131+
.build();
132+
127133
Option polFile = Option.builder("pol").longOpt("polFile").required(false).hasArg(true).desc("PolicyFile File")
128134
.build();
129135

@@ -148,6 +154,7 @@ private static Options options() {
148154
options.addOption(help);
149155
options.addOption(type);
150156
options.addOption(inSecure);
157+
options.addOption(fedDir);
151158
return options;
152159
}
153160

apim-deployment-project/gateway-standalone/src/main/java/com/axway/apim/Orchestrator.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.axway.apim;
22

3+
import java.io.File;
34
import java.io.IOException;
45
import java.net.URISyntaxException;
56
import java.security.KeyManagementException;
67
import java.security.KeyStoreException;
78
import java.security.NoSuchAlgorithmException;
89
import java.util.List;
10+
import java.util.UUID;
11+
import java.util.jar.Manifest;
912

1013
import static com.axway.apim.Constants.*;
1114

@@ -41,14 +44,22 @@ public void download(String url, String username, String password, String groupN
4144
}
4245

4346
public void deploy(String url, String username, String password, String groupName, String instanceName, String type,
44-
String fedFileName, String polFileName, String envFileName, boolean insecure) {
47+
String fedFileName, String polFileName, String envFileName, boolean insecure, String fedDir) {
4548
try {
4649
String archiveId = null;
4750
gatewayDeployment.init(url, username, password, insecure);
4851
String phyGroupName = gatewayDeployment.getPhysicalGroupName(groupName, url);
4952
List<String> servers = gatewayDeployment.getServerLists(url, instanceName, phyGroupName);
5053
if (type.equalsIgnoreCase("fed")) {
5154

55+
if (fedFileName == null && fedDir != null) {
56+
// Handle fed project
57+
Archive archive = new Archive();
58+
String uuidStr = UUID.randomUUID().toString();
59+
fedFileName = uuidStr + ".fed";
60+
Manifest manifest = archive.createManifest(uuidStr);
61+
archive.createFed(uuidStr, manifest, fedFileName, new File(fedDir));
62+
}
5263
archiveId = gatewayDeployment.uploadFed(phyGroupName, FED_ATTACHMENT_NAME, url, fedFileName,
5364
servers);
5465

0 commit comments

Comments
 (0)