Commit 781e2b50 by natalya

initial commit

parents
# Intellij
.idea/
*.iml
*.iws
# Mac
.DS_Store
# Maven
log/
target/
# Maven release plugin files
release.properties
pom.xml.releaseBackup
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>kz.arta.ext</groupId>
<artifactId>jboss-deployments-manager</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<powermock.version>1.6.5</powermock.version>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package kz.arta.ext.jdm.config;
import kz.arta.ext.jdm.config.model.Deployment;
import kz.arta.ext.jdm.config.model.Deployments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.xml.bind.JAXB;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
/**
* Created by timur on 10/10/16.
*/
public class Config {
private static final Logger LOGGER = LoggerFactory.getLogger(Config.class);
private String filePath = "/opt/synergy/jdm/deployments.xml";
private String deploymentsPath = "/opt/synergy/jboss/standalone/deployments";
private String tmpPath = "/opt/tmpDeployments";
private Deployments deployments;
private Config() {
readConfig();
}
private static Config config = null;
public static Config getInstance() {
if (config == null) {
config = new Config();
}
return config;
}
private void readConfig() {
FileInputStream fin = null;
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
fin = new FileInputStream(filePath);
byte[] buffer = new byte[1024];
int read;
while ((read = fin.read(buffer, 0, buffer.length)) != -1) {
bout.write(buffer, 0, read);
}
deployments = JAXB.unmarshal(new ByteArrayInputStream(bout.toByteArray()), Deployments.class);
} catch (Exception exc){
LOGGER.error(exc.getMessage(), exc);
} finally {
try {
fin.close();
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
}
public String getDeploymentsPath() {
return deploymentsPath;
}
public String getTmpPath() {
return tmpPath;
}
public Deployments getDeployments() {
return deployments;
}
}
package kz.arta.ext.jdm.config;
/**
* Created by timur on 10/10/16.
*/
public class DeploymentsDirectoryObserver extends Thread {
private DirectoryViewer viewer = new DirectoryViewer();
private FileUtil fileUtil = new FileUtil();
@Override
public void run() {
}
}
package kz.arta.ext.jdm.config;
import kz.arta.ext.jdm.config.model.Deployment;
import kz.arta.ext.jdm.config.model.Deployments;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* Created by timur on 10/11/16.
*/
public class DeploymentsList {
private HashMap <String, DeploymentItem> items = new HashMap<>();
public DeploymentsList(Deployments deployments) {
for (Deployment deployment: deployments.getDeployments()) {
DeploymentItem item = null;
if (items.containsKey(deployment.getName())) {
item = items.get(deployment.getName());
} else {
item = new DeploymentItem();
item.fileName = deployment.getName();
items.put(item.fileName, item);
}
item.dependsOnList.add(deployment.getDependsOn());
}
}
private class DeploymentItem {
String fileName;
List<String> dependsOnList = new ArrayList<>();
boolean isDeployed;
}
}
package kz.arta.ext.jdm.config;
import kz.arta.ext.jdm.config.model.Deployment;
import kz.arta.ext.jdm.config.model.Deployments;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
/**
* Created by timur on 10/10/16.
*/
public class DirectoryViewer {
private List<String> getDeployedList() {
String[] files = new File(Config.getInstance().getDeploymentsPath()).list();
HashSet<String> deploymentsSet = new HashSet();
HashSet<String> serviceFilesSet = new HashSet();
for (String file: files) {
if (file.endsWith("ear") || file.endsWith("jar") || file.endsWith("war")) {
deploymentsSet.add(file);
} else {
serviceFilesSet.add(file);
}
}
List<String> deployedList = new ArrayList<String>();
for (String str: deploymentsSet) {
if (serviceFilesSet.contains(str + ".deployed")) {
deployedList.add(str);
}
}
return deployedList;
}
public List<String> getReadyToDeployList() {
List<String> deployed = getDeployedList();
Deployments deployments = Config.getInstance().getDeployments();
for (Deployment deployment: deployments.getDeployments()) {
}
return null;
}
}
package kz.arta.ext.jdm.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.file.*;
/**
* Created by timur on 10/10/16.
*/
public class FileUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(FileUtil.class);
public void moveFileBeforeStart(String fileName) {
try {
Files.move(FileSystems.getDefault().getPath(Config.getInstance().getDeploymentsPath(), fileName),
FileSystems.getDefault().getPath(Config.getInstance().getTmpPath()), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception exc) {
LOGGER.error(exc.getMessage(), exc);
}
}
public void moveFileOnDeployed(String fileName) {
try {
Files.move(FileSystems.getDefault().getPath(Config.getInstance().getTmpPath(), fileName),
FileSystems.getDefault().getPath(Config.getInstance().getDeploymentsPath()), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception exc) {
LOGGER.error(exc.getMessage(), exc);
}
}
}
package kz.arta.ext.jdm.config.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import java.util.List;
/**
* Created by topa on 10/10/16.
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class Deployment {
@XmlAttribute(name = "name")
private String name;
@XmlAttribute(name = "dependsOn")
private String dependsOn;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDependsOn() {
return dependsOn;
}
public void setDependsOn(String dependsOn) {
this.dependsOn = dependsOn;
}
}
package kz.arta.ext.jdm.config.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;
/**
* Created by timur on 10/10/16.
*/
@XmlRootElement(name = "deployments")
@XmlAccessorType(XmlAccessType.FIELD)
public class Deployments {
@XmlElement(name = "deployment")
private List<Deployment> deployments = new ArrayList<Deployment>();
public List<Deployment> getDeployments() {
return deployments;
}
public void setDeployments(List<Deployment> deployments) {
this.deployments = deployments;
}
}
package kz.arta.ext.jdm.config;
import kz.arta.ext.jdm.config.model.Deployments;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.reflect.Whitebox;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* Created by timur on 10/10/16.
*/
public class ConfigTest {
@Test
public void testReadConfig() throws Exception{
Config config = PowerMockito.mock(Config.class);
Whitebox.setInternalState(config, "filePath", ConfigTest.class.getResource("/kz/arta/jdm/config/config.xml").getFile());
Whitebox.invokeMethod(config, "readConfig");
Deployments deployments = Whitebox.getInternalState(config, "deployments");
Assert.assertEquals(deployments.getDeployments().size(), 2);
}
}
<deployments>
<deployment name="ear1" dependsOn="ear0"/>
<deployment name="ear2" dependsOn="ear1"/>
</deployments>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment