Search in sources :

Example 6 with EnvironmentUnit

use of com.axway.ats.environment.EnvironmentUnit in project ats-framework by Axway.

the class ComponentEnvironment method restore.

public void restore(String folderPath) throws AgentException {
    // All additional actions are implicitly added to the Additional Actions Queue Instance
    try {
        for (EnvironmentUnit environmentUnit : environmentUnits) {
            environmentUnit.setTempBackupDir(folderPath);
            environmentUnit.restore();
        }
    } catch (EnvironmentCleanupException ece) {
        throw new AgentException("Could not restore environment for component '" + this.componentName + "'" + recurseCauses(ece), ece);
    }
    // Now execute the additional actions and clean the queue
    try {
        AdditionalActionsQueue.getInstance().flushAllActions();
    } catch (EnvironmentCleanupException ece) {
        throw new AgentException("Could not restore environment for component '" + this.componentName + "'" + recurseCauses(ece), ece);
    }
}
Also used : EnvironmentCleanupException(com.axway.ats.environment.EnvironmentCleanupException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) EnvironmentUnit(com.axway.ats.environment.EnvironmentUnit) FileEnvironmentUnit(com.axway.ats.environment.file.FileEnvironmentUnit) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) DirectoryEnvironmentUnit(com.axway.ats.environment.file.DirectoryEnvironmentUnit)

Example 7 with EnvironmentUnit

use of com.axway.ats.environment.EnvironmentUnit in project ats-framework by Axway.

the class Test_DirectoryEnvironmentUnit method restore_aNewFileMustBeDeleted.

// TODO - investigate failing error. It is just on CI machine, only when run from Jenkins
@Ignore
@Test
public void restore_aNewFileMustBeDeleted() throws EnvironmentCleanupException, IOException {
    EnvironmentUnit dirEnvUnit = new DirectoryEnvironmentUnit(restoreDirPath, backupDirPath, backupDirName);
    Assert.assertTrue(dirEnvUnit.restore());
    new File(restoreDirPath + "newFile.txt").createNewFile();
    // now the restore is not needed
    Assert.assertTrue(dirEnvUnit.restore());
}
Also used : EnvironmentUnit(com.axway.ats.environment.EnvironmentUnit) File(java.io.File) Ignore(org.junit.Ignore) BaseTest(com.axway.ats.environment.BaseTest) Test(org.junit.Test)

Example 8 with EnvironmentUnit

use of com.axway.ats.environment.EnvironmentUnit in project ats-framework by Axway.

the class Test_DirectoryEnvironmentUnit method restore.

@Test
public void restore() throws EnvironmentCleanupException {
    EnvironmentUnit dirEnvUnit = new DirectoryEnvironmentUnit(restoreDirPath, backupDirPath, backupDirName);
    Assert.assertTrue(dirEnvUnit.restore());
}
Also used : EnvironmentUnit(com.axway.ats.environment.EnvironmentUnit) BaseTest(com.axway.ats.environment.BaseTest) Test(org.junit.Test)

Example 9 with EnvironmentUnit

use of com.axway.ats.environment.EnvironmentUnit in project ats-framework by Axway.

the class Test_ConfigurationParser method getEnvironmentUnitsWithPort.

@Test
public void getEnvironmentUnitsWithPort() throws Exception {
    InputStream descriptorFileStream = Test_ConfigurationParser.class.getResourceAsStream("descriptor_with_port.xml");
    ConfigurationParser configParser = new ConfigurationParser();
    configParser.parse(descriptorFileStream, jarFileAbsolutePath);
    List<EnvironmentUnit> environmentUnits = configParser.getEnvironments().get(0).getEnvironmentUnits();
    assertEquals(3, environmentUnits.size());
    assertEquals(DatabaseEnvironmentUnit.class, environmentUnits.get(0).getClass());
    assertEquals(FileEnvironmentUnit.class, environmentUnits.get(1).getClass());
    assertEquals(FileEnvironmentUnit.class, environmentUnits.get(2).getClass());
    // check connection properties
    DatabaseEnvironmentUnit dbUnit = (DatabaseEnvironmentUnit) configParser.getEnvironments().get(0).getEnvironmentUnits().get(0);
    assertEquals("127.127.127.127", dbUnit.getDbConnection().getHost());
    assertEquals("st", dbUnit.getDbConnection().getDb());
    assertEquals("root", dbUnit.getDbConnection().getUser());
    assertEquals("axway", dbUnit.getDbConnection().getPassword());
    assertEquals("mysql".toUpperCase(), dbUnit.getDbConnection().getDbType().toString());
    Map<String, Object> customDbConnectionProperties = dbUnit.getDbConnection().getCustomProperties();
    assertEquals(33060, customDbConnectionProperties.get(DbKeys.PORT_KEY));
}
Also used : InputStream(java.io.InputStream) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) FileEnvironmentUnit(com.axway.ats.environment.file.FileEnvironmentUnit) EnvironmentUnit(com.axway.ats.environment.EnvironmentUnit) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) DirectoryEnvironmentUnit(com.axway.ats.environment.file.DirectoryEnvironmentUnit) Test(org.junit.Test)

Example 10 with EnvironmentUnit

use of com.axway.ats.environment.EnvironmentUnit in project ats-framework by Axway.

the class ComponentEnvironment method backup.

public void backup(String folderPath) throws AgentException {
    log.info("Backuping environment for component " + componentName);
    try {
        String currentBackupFolder = backupFolder;
        if (folderPath != null) {
            currentBackupFolder = folderPath;
        }
        //if the current backup folder already exists and is not empty, we will rename it in order to have
        //a clean backup and to save the previous backup data
        File backupDir = new File(currentBackupFolder);
        if (backupDir.isDirectory() && backupDir.list().length > 0) {
            String backupFolderPath = currentBackupFolder;
            if (currentBackupFolder.endsWith("/") || currentBackupFolder.endsWith("\\")) {
                backupFolderPath = currentBackupFolder.substring(0, currentBackupFolder.length() - 1);
            }
            backupFolderPath = backupFolderPath + BACKUP_DATE_FORMATTER.format(new Date());
            backupFolderPath = IoUtils.normalizeDirPath(backupFolderPath);
            log.info("In order to have a clean backup, we'll rename the current backup folder: " + backupFolderPath);
            backupDir.renameTo(new File(backupFolderPath));
        }
        for (EnvironmentUnit environmentUnit : environmentUnits) {
            environmentUnit.setTempBackupDir(folderPath);
            environmentUnit.backup();
        }
    } catch (EnvironmentCleanupException ece) {
        throw new AgentException("Could not backup environment for component " + componentName + recurseCauses(ece), ece);
    }
}
Also used : EnvironmentCleanupException(com.axway.ats.environment.EnvironmentCleanupException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) EnvironmentUnit(com.axway.ats.environment.EnvironmentUnit) FileEnvironmentUnit(com.axway.ats.environment.file.FileEnvironmentUnit) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) DirectoryEnvironmentUnit(com.axway.ats.environment.file.DirectoryEnvironmentUnit) File(java.io.File) Date(java.util.Date)

Aggregations

EnvironmentUnit (com.axway.ats.environment.EnvironmentUnit)18 Test (org.junit.Test)11 DatabaseEnvironmentUnit (com.axway.ats.environment.database.DatabaseEnvironmentUnit)10 BaseTest (com.axway.ats.environment.BaseTest)8 DirectoryEnvironmentUnit (com.axway.ats.environment.file.DirectoryEnvironmentUnit)8 FileEnvironmentUnit (com.axway.ats.environment.file.FileEnvironmentUnit)8 File (java.io.File)8 AgentException (com.axway.ats.agent.core.exceptions.AgentException)3 EnvironmentCleanupException (com.axway.ats.environment.EnvironmentCleanupException)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 Ignore (org.junit.Ignore)3 ComponentEnvironment (com.axway.ats.agent.core.ComponentEnvironment)2 Component (com.axway.ats.agent.core.Component)1 ComponentRepository (com.axway.ats.agent.core.ComponentRepository)1 NoSuchComponentException (com.axway.ats.agent.core.exceptions.NoSuchComponentException)1 DbConnection (com.axway.ats.core.dbaccess.DbConnection)1 DbConnMySQL (com.axway.ats.core.dbaccess.mysql.DbConnMySQL)1 SystemProcessAction (com.axway.ats.environment.process.SystemProcessAction)1 Date (java.util.Date)1