use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager in project phoss-smp by phax.
the class APIExecutorExportOutboundMigrationInProcessXMLVer 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 sLogPrefix = "[REST API Export-OutboundMigrationInProcess-XML-V1] ";
LOGGER.info(sLogPrefix + "Starting Export for all with outbound migration state 'in progress'");
// Only authenticated user may do so
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
SMPUserManagerPhoton.validateUserCredentials(aBasicAuth);
// Start action after authentication
final ISMPSettingsManager aSettingsMgr = SMPMetaManager.getSettingsMgr();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
final ICommonsList<ISMPParticipantMigration> aAllMigrations = aParticipantMigrationMgr.getAllOutboundParticipantMigrations(EParticipantMigrationState.IN_PROGRESS);
// Now get all relevant service groups
final ICommonsList<ISMPServiceGroup> aAllServiceGroups = new CommonsArrayList<>();
for (final ISMPParticipantMigration aMigration : aAllMigrations) {
final ISMPServiceGroup aSG = aServiceGroupMgr.getSMPServiceGroupOfID(aMigration.getParticipantIdentifier());
if (aSG != null)
aAllServiceGroups.add(aSG);
else
LOGGER.warn(sLogPrefix + "Failed to resolve PID '" + aMigration.getParticipantIdentifier().getURIEncoded() + "' to a Service Group");
}
final boolean bIncludeBusinessCards = aRequestScope.params().getAsBoolean(PARAM_INCLUDE_BUSINESS_CARDS, aSettingsMgr.getSettings().isDirectoryIntegrationEnabled());
final IMicroDocument aDoc = ServiceGroupExport.createExportDataXMLVer10(aAllServiceGroups, bIncludeBusinessCards);
LOGGER.info(sLogPrefix + "Finished creating Export data");
// Build the XML response
final IXMLWriterSettings aXWS = new XMLWriterSettings();
aUnifiedResponse.setContentAndCharset(MicroWriter.getNodeAsString(aDoc, aXWS), aXWS.getCharset()).setMimeType(new MimeType(CMimeType.APPLICATION_XML).addParameter(CMimeType.PARAMETER_NAME_CHARSET, aXWS.getCharset().name())).disableCaching();
}
use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager in project phoss-smp by phax.
the class APIExecutorMigrationInboundFromPathPut method migrationInbound.
public static void migrationInbound(@Nonnull final String sServiceGroupID, @Nonnull final String sMigrationKey, @Nonnull final String sLogPrefix, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws SMPServerException, GeneralSecurityException {
LOGGER.info(sLogPrefix + "Starting inbound migration for Service Group ID '" + sServiceGroupID + "' and migration key '" + sMigrationKey + "'");
// Only authenticated user may do so
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
final IUser aOwningUser = SMPUserManagerPhoton.validateUserCredentials(aBasicAuth);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sServiceGroupID);
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 aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
if (aParticipantID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sServiceGroupID, aDataProvider.getCurrentURI());
}
// Check that service group does not exist yet
if (aServiceGroupMgr.containsSMPServiceGroupWithID(aParticipantID)) {
throw new SMPBadRequestException("The Service Group '" + sServiceGroupID + "' already exists.", aDataProvider.getCurrentURI());
}
if (false) {
// valid
if (aParticipantMigrationMgr.containsInboundMigration(aParticipantID)) {
throw new SMPBadRequestException("The inbound migration of the Service Group '" + sServiceGroupID + "' is already contained.", aDataProvider.getCurrentURI());
}
}
// create the Service Group locally
try {
final ManageParticipantIdentifierServiceCaller aCaller = new ManageParticipantIdentifierServiceCaller(aSettings.getSMLInfo());
aCaller.setSSLSocketFactory(SMPKeyManager.getInstance().createSSLContext().getSocketFactory());
// SML call
aCaller.migrate(aParticipantID, sMigrationKey, SMPServerConfiguration.getSMLSMPID());
LOGGER.info(sLogPrefix + "Successfully migrated '" + aParticipantID.getURIEncoded() + "' in the SML to this SMP using migration key '" + sMigrationKey + "'");
} catch (final BadRequestFault | InternalErrorFault | NotFoundFault | UnauthorizedFault | ClientTransportException ex) {
throw new SMPSMLException("Failed to confirm the migration for participant '" + aParticipantID.getURIEncoded() + "' in SML, hence the migration failed." + " Please check the participant identifier and the migration key.", ex);
}
// Now create the service group locally (it was already checked that the
// PID is available on this SMP)
ISMPServiceGroup aSG = null;
Exception aCaughtEx = null;
try {
// Do not allow any Extension here
// Do NOT create in SMK/SML
aSG = aServiceGroupMgr.createSMPServiceGroup(aOwningUser.getID(), aParticipantID, (String) null, false);
} catch (final Exception ex) {
aCaughtEx = ex;
}
if (aSG != null) {
LOGGER.info(sLogPrefix + "The new SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "' was successfully created.");
} else {
// No exception here
LOGGER.error(sLogPrefix + "Error creating the new SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "'.", aCaughtEx);
}
// Remember internally
final ISMPParticipantMigration aMigration = aParticipantMigrationMgr.createInboundParticipantMigration(aParticipantID, sMigrationKey);
if (aMigration != null) {
LOGGER.info(sLogPrefix + "The participant migration for '" + aParticipantID.getURIEncoded() + "' with migration key '" + sMigrationKey + "' was successfully performed. Please inform the source SMP that the migration was successful.");
} else {
// No exception here
LOGGER.error(sLogPrefix + "Failed to store the participant migration for '" + aParticipantID.getURIEncoded() + "'.");
}
final IMicroDocument aResponseDoc = new MicroDocument();
final IMicroElement eRoot = aResponseDoc.appendElement("migrationInboundResponse");
eRoot.setAttribute("success", aSG != null && aMigration != null);
eRoot.setAttribute("serviceGroupCreated", aSG != null);
eRoot.setAttribute("migrationCreated", aMigration != null);
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();
}
use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager in project phoss-smp by phax.
the class APIExecutorMigrationOutboundCancelPut 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. migrationOutboundCancel will not be executed", aDataProvider.getCurrentURI());
}
final String sLogPrefix = "[REST API Migration-Outbound-Cancel] ";
LOGGER.info(sLogPrefix + "Cancelling outbound Participant 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 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());
}
final String sMigrationID = aMigration.getID();
LOGGER.info(sLogPrefix + "Found the outbound Participant Migration ID '" + sMigrationID + "' with state " + aMigration.getState() + " for the Service Group ID '" + sServiceGroupID + "'");
// Change migration state
if (aParticipantMigrationMgr.setParticipantMigrationState(sMigrationID, EParticipantMigrationState.CANCELLED).isUnchanged()) {
throw new SMPBadRequestException("Failed to cancel the outbound Participant Migration with ID '" + sMigrationID + "'", aDataProvider.getCurrentURI());
}
LOGGER.info(sLogPrefix + "The outbound Participant Migration with ID '" + sMigrationID + "' on Service Group ID '" + sServiceGroupID + "' was successfully cancelled!");
aUnifiedResponse.setStatus(CHttp.HTTP_OK).disableCaching();
}
use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager in project phoss-smp by phax.
the class PageSecureServiceGroupMigrationOutbound method validateAndSaveInputParameters.
@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMPParticipantMigration aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final ISMPSettings aSettings = SMPMetaManager.getSettings();
final String sParticipantID = aWPEC.params().getAsStringTrimmed(FIELD_PARTICIPANT_ID);
final IParticipantIdentifier aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sParticipantID);
if (StringHelper.hasNoText(sParticipantID))
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "A Service Group must be selected.");
else if (aParticipantID == null)
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "The selected Service Group does not exist.");
else {
if (aParticipantMigrationMgr.containsOutboundMigrationInProgress(aParticipantID))
aFormErrors.addFieldError(FIELD_PARTICIPANT_ID, "The migration of the selected Service Group is already in progress.");
}
if (aFormErrors.isEmpty()) {
LOGGER.info("Starting migration of participant ID '" + aParticipantID.getURIEncoded() + "'");
// Lets take this to the SML
String sMigrationKey = null;
if (true) {
try {
final ManageParticipantIdentifierServiceCaller aCaller = new ManageParticipantIdentifierServiceCaller(aSettings.getSMLInfo());
aCaller.setSSLSocketFactory(SMPKeyManager.getInstance().createSSLContext().getSocketFactory());
// Create a random migration key,
// Than call SML
sMigrationKey = aCaller.prepareToMigrate(aParticipantID, SMPServerConfiguration.getSMLSMPID());
LOGGER.info("Successfully called prepareToMigrate on SML. Created migration key is '" + sMigrationKey + "'");
} catch (final Exception ex) {
LOGGER.error("Error invoking prepareToMigrate on SML", ex);
aWPEC.postRedirectGetInternal(error("Failed to prepare the migration for participant '" + aParticipantID.getURIEncoded() + "' in SML.").addChild(SMPCommonUI.getTechnicalDetailsUI(ex)));
}
} else {
// Dummy for testing only
sMigrationKey = ManageParticipantIdentifierServiceCaller.createRandomMigrationKey();
LOGGER.warn("Created migration key '" + sMigrationKey + "' was not send to SML!");
}
// Remember internally
if (aParticipantMigrationMgr.createOutboundParticipantMigration(aParticipantID, sMigrationKey) != null) {
aWPEC.postRedirectGetInternal(success().addChild(div("The participant migration for '" + aParticipantID.getURIEncoded() + "' was successfully created.")).addChild(div("The created migration key is ").addChild(code(sMigrationKey))));
} else {
aWPEC.postRedirectGetInternal(error().addChild(div("Failed to store the participant migration for '" + aParticipantID.getURIEncoded() + "'.")).addChild(div("The created migration key is ").addChild(code(sMigrationKey))).addChild(". Please note it down manually!"));
}
}
}
use of com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigrationManager in project phoss-smp by phax.
the class PageSecureServiceGroupMigrationOutbound method showListOfExistingObjects.
@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
final ISMPSettings aSettings = SMPMetaManager.getSettings();
final ISMPServiceGroupManager aServiceGroupManager = SMPMetaManager.getServiceGroupMgr();
{
final HCOL aOL = new HCOL();
aOL.addItem("The migration is initiated on this SMP, and the SML is informed about the upcoming migration");
aOL.addItem("The other SMP, that is taking over the Service Group, must acknowledge the migration by providing the same migration code (created by this SMP) to the SML");
aOL.addItem("If the migration was successful, the Service Group must be deleted from this SMP, ideally a temporary redirect to the new SMP is created. If the migration was cancelled no action is needed.");
aNodeList.addChild(info().addChild(div("The process of migrating a Service Group to another SMP consists of multiple steps:")).addChild(aOL).addChild(div("Therefore each open Migration must either be finished (deleting the Service Group) or cancelled (no action taken)." + " If a Migration is cancelled, it can be retried later.")));
}
EValidity eCanStartMigration = EValidity.VALID;
if (aSettings.getSMLInfo() == null) {
final BootstrapWarnBox aWarn = aNodeList.addAndReturnChild(warn().addChild(div("No valid SML Configuration is selected hence no participant can be migrated.")).addChild(div(new BootstrapButton().addChild("Select SML Configuration in the Settings").setOnClick(aWPEC.getLinkToMenuItem(CMenuSecure.MENU_SMP_SETTINGS)).setIcon(EDefaultIcon.EDIT))));
if (aSettings.isSMLEnabled() || aSettings.isSMLRequired()) {
aWarn.addChild(div(new BootstrapButton().addChild("Create a new SML Configuration").setOnClick(createCreateURL(aWPEC, CMenuSecure.MENU_SML_CONFIGURATION)).setIcon(EDefaultIcon.YES)));
}
eCanStartMigration = EValidity.INVALID;
} else if (!aSettings.isSMLEnabled()) {
aNodeList.addChild(warn().addChild(div("SML Connection is not enabled hence no participant can be migrated.")).addChild(div(new BootstrapButton().addChild("Enable SML in the Settings").setOnClick(aWPEC.getLinkToMenuItem(CMenuSecure.MENU_SMP_SETTINGS)).setIcon(EDefaultIcon.EDIT))));
eCanStartMigration = EValidity.INVALID;
} else {
if (aServiceGroupManager.getSMPServiceGroupCount() <= 0) {
aNodeList.addChild(warn("No Service Group is present! At least one Service Group must be present to migrate it."));
// Note: makes no to allow to create a new Service Group here and than
// directly migrate it away
eCanStartMigration = EValidity.INVALID;
}
}
{
final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
aToolbar.addChild(new BootstrapButton().addChild("Start Participant Migration").setOnClick(createCreateURL(aWPEC)).setDisabled(eCanStartMigration.isInvalid()).setIcon(EDefaultIcon.NEW));
aNodeList.addChild(aToolbar);
}
final BootstrapTabBox aTabBox = aNodeList.addAndReturnChild(new BootstrapTabBox());
final ICommonsList<ISMPParticipantMigration> aAllMigs = aParticipantMigrationMgr.getAllOutboundParticipantMigrations(null);
for (final EParticipantMigrationState eState : EParticipantMigrationState.values()) if (eState.isOutboundState()) {
final ICommonsList<ISMPParticipantMigration> aMatchingMigs = aAllMigs.getAll(x -> x.getState() == eState);
aTabBox.addTab(eState.getID(), eState.getDisplayName() + " (" + aMatchingMigs.size() + ")", _createTable(aWPEC, aMatchingMigs, eState));
}
}
Aggregations