use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class AMSetupServlet method createOpenDJBackup.
private static void createOpenDJBackup() {
try {
UpgradeDirectoryUtils.createUpgradeDirectories(getBaseDir());
} catch (UpgradeException ue) {
Debug.getInstance(SetupConstants.DEBUG_NAME).error("Upgrade cannot create backup directory", ue);
return;
}
ZipOutputStream zOut = null;
String baseDir = getBaseDir();
String backupDir = baseDir + "/backups/";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String dateStamp = dateFormat.format(new Date());
File backupFile = new File(backupDir + "opendj.backup." + dateStamp + ".zip");
if (backupFile.exists()) {
Debug.getInstance(SetupConstants.DEBUG_NAME).error("Upgrade cannot continue as backup file exists! " + backupFile.getName());
return;
}
File opendjDirectory = new File(baseDir + OPENDS_DIR);
if (opendjDirectory.exists() && opendjDirectory.isDirectory()) {
final String[] filenames = opendjDirectory.list();
try {
zOut = new ZipOutputStream(new FileOutputStream(backupFile));
// Compress the files
for (String filename : filenames) {
zipDir(new File(baseDir + OPENDS_DIR + File.separator + filename), baseDir + OPENDS_DIR + File.separator, zOut, (baseDir + File.separator).length());
}
zOut.close();
} catch (IOException ioe) {
Debug.getInstance(SetupConstants.DEBUG_NAME).error("IOException", ioe);
} finally {
if (zOut != null) {
try {
zOut.close();
} catch (IOException ioe) {
// do nothing
}
}
}
}
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class BootstrapData method initSMS.
public void initSMS(boolean startDS) throws UnsupportedEncodingException, LDAPServiceException, MalformedURLException {
String serverConfigXML = getServerConfigXML(false);
Properties prop = getBootstrapProperties();
SystemProperties.initializeProperties(prop, true);
Crypt.reinitialize();
loadServerConfigXML(serverConfigXML);
if (startDS) {
startEmbeddedDS(basedir + AMSetupServlet.OPENDS_DIR);
if (AMSetupServlet.isOpenDJUpgraded()) {
try {
new DirectoryContentUpgrader(basedir, dsbasedn).upgrade(true);
} catch (UpgradeException ue) {
throw new IllegalStateException("An error occurred while upgrading directory content", ue);
}
}
} else {
EmbeddedOpenDS.initializeForClientUse();
}
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class ServiceSchemaModifications method parseExistingServiceDefinition.
private void parseExistingServiceDefinition() throws UpgradeException {
//we should only fetch these once to prevent performance problems, also in case of fetchNew to prevent
//encrypting passwords multiple times.
Map<String, ServiceSchemaImpl> newSchemaMap = fetchNewServiceAttributes(serviceSchemaDoc);
Map<String, ServiceSchemaImpl> existingSchemaMap = null;
try {
existingSchemaMap = fetchExistingServiceAttributes(serviceName, adminToken);
} catch (SMSException smse) {
UpgradeUtils.debug.error("unable to fetch existing service attributes", smse);
throw new UpgradeException(smse.getMessage());
} catch (SSOException ssoe) {
UpgradeUtils.debug.error("unable to fetch existing service attributes", ssoe);
throw new UpgradeException(ssoe.getMessage());
}
if (calculateSchemaChanges(newSchemaMap, existingSchemaMap)) {
if (UpgradeUtils.debug.messageEnabled()) {
UpgradeUtils.debug.message("service " + serviceName + " has new/deleted schema");
}
hasSchemaChanges = true;
}
// sub schemas added or removed?
if (calculateSubSchemaChanges(newSchemaMap, existingSchemaMap)) {
if (UpgradeUtils.debug.messageEnabled()) {
UpgradeUtils.debug.message("service " + serviceName + " has a modified sub schema");
}
hasSubSchemaChanges = true;
}
// has the service changed
if (calculateServiceModifications(newSchemaMap, existingSchemaMap)) {
if (UpgradeUtils.debug.messageEnabled()) {
UpgradeUtils.debug.message("service " + serviceName + " has changes in schemas");
}
isServiceModified = true;
}
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class ServiceSchemaModifications method calculateServiceModifications.
private boolean calculateServiceModifications(Map<String, ServiceSchemaImpl> newSchemaMap, Map<String, ServiceSchemaImpl> existingSchemaMap) throws UpgradeException {
modifications = new HashMap<String, ServiceSchemaUpgradeWrapper>();
try {
for (Map.Entry<String, ServiceSchemaImpl> newAttrSchemaEntry : newSchemaMap.entrySet()) {
ServiceSchemaImpl schema = existingSchemaMap.get(newAttrSchemaEntry.getKey());
if (schema == null) {
//calculateSchemaChanges
continue;
}
ServiceSchemaModificationWrapper attrsAdded = getServiceAdditionsRecursive(newAttrSchemaEntry.getKey(), newAttrSchemaEntry.getValue(), schema);
ServiceSchemaModificationWrapper attrsModified = getServiceModificationsRecursive(newAttrSchemaEntry.getKey(), newAttrSchemaEntry.getValue(), schema);
ServiceSchemaModificationWrapper attrsDeleted = getServiceDeletionsRecursive(newAttrSchemaEntry.getKey(), newAttrSchemaEntry.getValue(), schema);
if (attrsAdded.hasBeenModified() || attrsModified.hasBeenModified() || attrsDeleted.hasBeenModified()) {
modifications.put(newAttrSchemaEntry.getKey(), new ServiceSchemaUpgradeWrapper(attrsAdded, attrsModified, attrsDeleted));
}
}
} catch (SMSException smse) {
UpgradeUtils.debug.error("error whilst determining schema changes for service: " + serviceName, smse);
throw new UpgradeException(smse.getMessage());
}
if (UpgradeUtils.debug.messageEnabled()) {
UpgradeUtils.debug.message("calculateServiceModifications returning " + (!(modifications.isEmpty())));
}
return !(modifications.isEmpty());
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class ServiceSchemaModifications method createServiceModifications.
/**
* This will use the service schemas to find any upgrade handlers registered for the service and
* populate the NewServiceWrapper's ServiceSchemaModificationWrappers.
* @param newSchemaMap The service schemas representing the service.
* @throws UpgradeException If an upgrade error occurs.
*/
private void createServiceModifications(Map<String, ServiceSchemaImpl> newSchemaMap) throws UpgradeException {
try {
final Map<String, ServiceSchemaModificationWrapper> serviceSchemaMap = new HashMap<String, ServiceSchemaModificationWrapper>();
for (Map.Entry<String, ServiceSchemaImpl> newAttrSchemaEntry : newSchemaMap.entrySet()) {
final ServiceSchemaModificationWrapper attributesAdded = getServiceModificationsRecursive(newAttrSchemaEntry.getKey(), newAttrSchemaEntry.getValue());
if (attributesAdded.hasBeenModified()) {
serviceSchemaMap.put(newAttrSchemaEntry.getKey(), attributesAdded);
}
}
newServiceWrapper = new NewServiceWrapper(serviceName, serviceSchemaMap, serviceSchemaDoc);
} catch (SMSException smse) {
UpgradeUtils.debug.error("Error whilst determining schema changes for service: " + serviceName, smse);
throw new UpgradeException(smse.getMessage(), smse);
}
}
Aggregations