use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration in project phoss-smp by phax.
the class SMPParticipantMigrationManagerMongoDB method getAllOutboundParticipantMigrations.
@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPParticipantMigration> getAllOutboundParticipantMigrations(@Nullable final EParticipantMigrationState eState) {
Bson aFilter = new Document(BSON_DIRECTION, EParticipantMigrationDirection.OUTBOUND.getID());
if (eState != null)
aFilter = Filters.and(aFilter, new Document(BSON_STATE, eState.getID()));
final ICommonsList<ISMPParticipantMigration> ret = new CommonsArrayList<>();
getCollection().find(aFilter).forEach(x -> ret.add(toDomain(x)));
return ret;
}
use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration in project phoss-smp by phax.
the class SMPParticipantMigrationManagerMongoDB method getAllInboundParticipantMigrations.
@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPParticipantMigration> getAllInboundParticipantMigrations(@Nullable final EParticipantMigrationState eState) {
Bson aFilter = new Document(BSON_DIRECTION, EParticipantMigrationDirection.INBOUND.getID());
if (eState != null)
aFilter = Filters.and(aFilter, new Document(BSON_STATE, eState.getID()));
final ICommonsList<ISMPParticipantMigration> ret = new CommonsArrayList<>();
getCollection().find(aFilter).forEach(x -> ret.add(toDomain(x)));
return ret;
}
use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration in project phoss-smp by phax.
the class SMPParticipantMigrationManagerMongoDB method createInboundParticipantMigration.
@Nonnull
public ISMPParticipantMigration createInboundParticipantMigration(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull @Nonempty final String sMigrationKey) {
final SMPParticipantMigration aSMPParticipantMigration = SMPParticipantMigration.createInbound(aParticipantID, sMigrationKey);
_createParticipantMigration(aSMPParticipantMigration);
return aSMPParticipantMigration;
}
use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration in project phoss-smp by phax.
the class APIExecutorMigrationOutboundFinalizePut method invokeAPI.
public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
final String sServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sServiceGroupID);
// Is the writable API disabled?
if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
throw new SMPPreconditionFailedException("The writable REST API is disabled. migrationOutboundFinalize will not be executed", aDataProvider.getCurrentURI());
}
final String sLogPrefix = "[REST API Migration-Outbound-Finalize] ";
LOGGER.info(sLogPrefix + "Finalizing outbound migration for Service Group ID '" + sServiceGroupID + "'");
// Only authenticated user may do so
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
SMPUserManagerPhoton.validateUserCredentials(aBasicAuth);
final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
if (aServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sServiceGroupID, aDataProvider.getCurrentURI());
}
// Find matching migration object
final ISMPParticipantMigration aMigration = aParticipantMigrationMgr.getParticipantMigrationOfParticipantID(EParticipantMigrationDirection.OUTBOUND, EParticipantMigrationState.IN_PROGRESS, aServiceGroupID);
if (aMigration == null) {
throw new SMPBadRequestException("Failed to resolve outbound participant migration for Service Group ID '" + sServiceGroupID + "'", aDataProvider.getCurrentURI());
}
// Remember the old state
final String sMigrationID = aMigration.getID();
final EParticipantMigrationState eOldState = aMigration.getState();
// Migrate state
if (aParticipantMigrationMgr.setParticipantMigrationState(sMigrationID, EParticipantMigrationState.MIGRATED).isUnchanged()) {
throw new SMPBadRequestException("The participant migration with ID '" + sMigrationID + "' is already finalized", aDataProvider.getCurrentURI());
}
LOGGER.info(sLogPrefix + "The outbound Participant Migration with ID '" + sMigrationID + "' for '" + sServiceGroupID + "' was successfully finalized!");
try {
// in the SML
if (aServiceGroupMgr.deleteSMPServiceGroup(aServiceGroupID, false).isChanged()) {
LOGGER.info(sLogPrefix + "The SMP Service Group for participant '" + sServiceGroupID + "' was successfully deleted from this SMP (without SML)!");
} else {
throw new SMPBadRequestException("The SMP Service Group for participant '" + sServiceGroupID + "' could not be deleted", aDataProvider.getCurrentURI());
}
} catch (final SMPServerException ex) {
// manager
if (aParticipantMigrationMgr.setParticipantMigrationState(sMigrationID, eOldState).isChanged()) {
LOGGER.warn(sLogPrefix + "Successfully reverted the state of the outbound Participant Migration for '" + sServiceGroupID + "' to " + eOldState + "!");
} else {
// Error in error handling. Yeah
LOGGER.error(sLogPrefix + "Failed to revert the state of the outbound Participant Migration for '" + sServiceGroupID + "' to " + eOldState + "!");
}
throw ex;
}
aUnifiedResponse.setStatus(CHttp.HTTP_OK).disableCaching();
}
use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration in project phoss-smp by phax.
the class APIExecutorMigrationOutboundStartPut method invokeAPI.
public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
final String sServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sServiceGroupID);
// Is the writable API disabled?
if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
throw new SMPPreconditionFailedException("The writable REST API is disabled. migrationOutboundStart will not be executed", aDataProvider.getCurrentURI());
}
final String sLogPrefix = "[REST API Migration-Outbound-Start] ";
LOGGER.info(sLogPrefix + "Starting outbound migration for Service Group ID '" + sServiceGroupID + "'");
// Only authenticated user may do so
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
SMPUserManagerPhoton.validateUserCredentials(aBasicAuth);
final ISMPSettings aSettings = SMPMetaManager.getSettings();
final ISMLInfo aSMLInfo = aSettings.getSMLInfo();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
if (aSMLInfo == null) {
throw new SMPPreconditionFailedException("Currently no SML is available. Please select it in the UI at the 'SMP Settings' page", aDataProvider.getCurrentURI());
}
if (!aSettings.isSMLEnabled()) {
throw new SMPPreconditionFailedException("SML Connection is not enabled hence no participant can be migrated", aDataProvider.getCurrentURI());
}
final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
if (aServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sServiceGroupID, aDataProvider.getCurrentURI());
}
// Check that service group exists
if (!aServiceGroupMgr.containsSMPServiceGroupWithID(aServiceGroupID)) {
throw new SMPBadRequestException("The Service Group '" + sServiceGroupID + "' does not exist", aDataProvider.getCurrentURI());
}
// Ensure no existing migration is in process
if (aParticipantMigrationMgr.containsOutboundMigrationInProgress(aServiceGroupID)) {
throw new SMPBadRequestException("The outbound Participant Migration of the Service Group '" + sServiceGroupID + "' is already in progress", aDataProvider.getCurrentURI());
}
String sMigrationKey = null;
try {
final ManageParticipantIdentifierServiceCaller aCaller = new ManageParticipantIdentifierServiceCaller(aSMLInfo);
aCaller.setSSLSocketFactory(SMPKeyManager.getInstance().createSSLContext().getSocketFactory());
// Create a random migration key,
// Than call SML
sMigrationKey = aCaller.prepareToMigrate(aServiceGroupID, SMPServerConfiguration.getSMLSMPID());
LOGGER.info(sLogPrefix + "Successfully called prepareToMigrate on SML. Created migration key is '" + sMigrationKey + "'");
} catch (final BadRequestFault | InternalErrorFault | NotFoundFault | UnauthorizedFault | ClientTransportException ex) {
throw new SMPSMLException("Failed to call prepareToMigrate on SML for Service Group '" + sServiceGroupID + "'", ex);
}
// Remember internally
final ISMPParticipantMigration aMigration = aParticipantMigrationMgr.createOutboundParticipantMigration(aServiceGroupID, sMigrationKey);
if (aMigration == null) {
throw new SMPInternalErrorException("Failed to create outbound Participant Migration for '" + sServiceGroupID + "' internally");
}
LOGGER.info(sLogPrefix + "Successfully created outbound Participant Migration with ID '" + aMigration.getID() + "' internally.");
// Build result
final IMicroDocument aResponseDoc = new MicroDocument();
final IMicroElement eRoot = aResponseDoc.appendElement("migrationOutboundResponse");
eRoot.setAttribute("success", true);
eRoot.appendElement(XML_ELEMENT_PARTICIPANT_ID).appendText(sServiceGroupID);
eRoot.appendElement(XML_ELEMENT_MIGRATION_KEY).appendText(sMigrationKey);
final XMLWriterSettings aXWS = new XMLWriterSettings().setIndent(EXMLSerializeIndent.INDENT_AND_ALIGN);
aUnifiedResponse.setContentAndCharset(MicroWriter.getNodeAsString(aResponseDoc, aXWS), aXWS.getCharset()).setMimeType(new MimeType(CMimeType.APPLICATION_XML).addParameter(CMimeType.PARAMETER_NAME_CHARSET, aXWS.getCharset().name())).disableCaching();
}
Aggregations