diff --git a/ucc/ucc.viewjambi/src/main/java/org/universAAL/ucc/viewjambi/install/DeployConfigView.java b/ucc/ucc.viewjambi/src/main/java/org/universAAL/ucc/viewjambi/install/DeployConfigView.java index 9524e128d58183ebf7996300f4921c59e683b979..a299a23d55e1b187ba223812ba176b5469678f9d 100644 --- a/ucc/ucc.viewjambi/src/main/java/org/universAAL/ucc/viewjambi/install/DeployConfigView.java +++ b/ucc/ucc.viewjambi/src/main/java/org/universAAL/ucc/viewjambi/install/DeployConfigView.java @@ -11,6 +11,7 @@ import java.util.Set; import org.universAAL.middleware.connectors.deploy.model.Part; import org.universAAL.middleware.interfaces.PeerCard; +import org.universAAL.middleware.managers.api.InstallationResults; import org.universAAL.ucc.viewjambi.common.SubWindow; import org.universAAL.ucc.viewjambi.impl.Activator; import org.universAAL.ucc.viewjambi.impl.MainWindow; @@ -122,7 +123,41 @@ public class DeployConfigView extends SubWindow { mpaLayout.put(card, part); } // call MW deploy manager requestToInstall - Activator.getInstaller().requestToInstall((new File(deployPath)).toURI(), mpaLayout); + InstallationResults results = Activator.getInstaller().requestToInstall((new File(deployPath)).toURI(), mpaLayout); + switch (results) { + case SUCCESS: + QMessageBox.information(this, "Installation result", "The multi-part application has been successfully installed!"); + System.out.println("[DeployConfigView.nextScreen] The multi-part application has been successfully installed!"); + break; + + case FAILED: + QMessageBox.information(this, "Installation result", "The installation of the multi-part application has been failed!"); + System.out.println("[DeployConfigView.nextScreen] The installation of the multi-part application has been failed!"); + break; + + case NO_AALSPACE_JOINED: + QMessageBox.information(this, "Installation result", "Error in the installation of the multi-part application: no AALspace joined!"); + System.out.println("[DeployConfigView.nextScreen] Error in the installation of the multi-part application: no AALspace joined!"); + break; + + case MPA_URI_INVALID: + QMessageBox.information(this, "Installation result", "Error in the installation of the multi-part application: MPA uri is invalid!"); + System.out.println("[DeployConfigView.nextScreen] Error in the installation of the multi-part application: MPA uri is invalid!"); + break; + + case DELEGATED: + QMessageBox.information(this, "Installation result", "The installation of the multi-part application is delegated..."); + System.out.println("[DeployConfigView.nextScreen] The installation of the multi-part application is delegated..."); + break; + + case LOCALLY_DELEGATED: + QMessageBox.information(this, "Installation result", "The installation of the multi-part application is locally delegated..."); + System.out.println("[DeployConfigView.nextScreen] The installation of the multi-part application is locally delegated..."); + break; + + default: + break; + } } return; diff --git a/ucc/ucc.viewjambi/src/main/java/org/universAAL/ucc/viewjambi/install/DeployStrategyView.java b/ucc/ucc.viewjambi/src/main/java/org/universAAL/ucc/viewjambi/install/DeployStrategyView.java new file mode 100644 index 0000000000000000000000000000000000000000..4b116aa0fb01910c8850fd2f3bc75ab9d05133f7 --- /dev/null +++ b/ucc/ucc.viewjambi/src/main/java/org/universAAL/ucc/viewjambi/install/DeployStrategyView.java @@ -0,0 +1,182 @@ +package org.universAAL.ucc.viewjambi.install; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.osgi.framework.Bundle; +import org.universAAL.middleware.connectors.deploy.model.AalMpa; +import org.universAAL.middleware.connectors.deploy.model.DeploymentUnit; +import org.universAAL.middleware.connectors.deploy.model.Part; +import org.universAAL.middleware.interfaces.PeerCard; +import org.universAAL.middleware.managers.api.InstallationResults; +import org.universAAL.ucc.viewjambi.common.SubWindow; +import org.universAAL.ucc.viewjambi.impl.Activator; +import org.universAAL.ucc.viewjambi.impl.MainWindow; +import org.universAAL.ucc.viewjambi.juic.Ui_DeployStrategyView; + +import com.trolltech.qt.gui.*; + +public class DeployStrategyView extends SubWindow { + + private static Ui_DeployStrategyView ui = new Ui_DeployStrategyView(); + boolean defaultStrategy = true; + String deployPath; + MpaParser mpaParser; + Map<String, PeerCard> peers; + + /** + * + * @param path deployPath, i.e., path of the extracted files from .uaal + */ + public DeployStrategyView(String path) { + super(DeployStrategyView.ui); + + deployPath = path; + mpaParser = new MpaParser(deployPath); + // TODO: get application name from .mpa file + //String appName = "MyApp"; + String appName = mpaParser.getAppName(); + // get the list of nodes in the AALspace + + // + + // initialization of the ui components + ui.lineEdit_appName.setText(appName); + ui.lineEdit_appName.setReadOnly(true); // disable text input (display only) + ui.radioButton_all.setChecked(true); + ui.radioButton_all.clicked.connect(this, "onAllNodes()"); + ui.radioButton_selected.clicked.connect(this, "onSelectedNodes()"); + + ui.pushButton_cancel.clicked.connect(this, "cancel()"); + ui.pushButton_ok.clicked.connect(this, "ok()"); + //ui.setupUi(this); + } + + private void onAllNodes() { + defaultStrategy = true; + } + + private void onSelectedNodes() { + defaultStrategy = false; + } + + private void ok() { + // get peers from AALSpaceManager + peers = Activator.getInstaller().getPeers(); + if (defaultStrategy) { + + Map config = buildDefaultInstallationLayout(); + InstallationResults results = Activator.getInstaller().requestToInstall((new File(deployPath)).toURI(), config); + switch (results) { + case SUCCESS: + QMessageBox.information(this, "Installation result", "The multi-part application has been successfully installed!"); + System.out.println("[DeployStrategyView.ok] The multi-part application has been successfully installed!"); + break; + + case FAILED: + QMessageBox.information(this, "Installation result", "The installation of the multi-part application has been failed!"); + System.out.println("[DeployStrategyView.ok] The installation of the multi-part application has been failed!"); + break; + + case NO_AALSPACE_JOINED: + QMessageBox.information(this, "Installation result", "Error in the installation of the multi-part application: no AALspace joined!"); + System.out.println("[DeployStrategyView.ok] Error in the installation of the multi-part application: no AALspace joined!"); + break; + + case MPA_URI_INVALID: + QMessageBox.information(this, "Installation result", "Error in the installation of the multi-part application: MPA uri is invalid!"); + System.out.println("[DeployStrategyView.ok] Error in the installation of the multi-part application: MPA uri is invalid!"); + break; + + case DELEGATED: + QMessageBox.information(this, "Installation result", "The installation of the multi-part application is delegated..."); + System.out.println("[DeployStrategyView.ok] The installation of the multi-part application is delegated..."); + break; + + case LOCALLY_DELEGATED: + QMessageBox.information(this, "Installation result", "The installation of the multi-part application is locally delegated..."); + System.out.println("[DeployStrategyView.ok] The installation of the multi-part application is locally delegated..."); + break; + + default: + break; + } + + } + else { + // allow user to select nodes to deploy + MainWindow.getInstance().removeSubWindow(this); + MainWindow.getInstance().deployConfigure(deployPath, mpaParser, peers); + } + + } + + /** + * Method to find the set of target peers according to the multipart application manifest + * @param mpa the MPA + * @return map of PeerCard of the target peers + */ + private Map<PeerCard, Part> buildDefaultInstallationLayout() { + //TODO: Do we need to check AAL space first (aalSpaceCheck)? + Map<PeerCard, Part> mpaLayout = new HashMap<PeerCard, Part>(); + Map<String, PeerCard> peersToCheck = new HashMap<String, PeerCard>(); + peersToCheck.putAll(peers); + for(Part part : mpaParser.getApplicationPart().getPart()){ + //check: deployment units + for(String key: peersToCheck.keySet()){ + PeerCard peer = peersToCheck.get(key); + if(checkDeployementUnit(part.getDeploymentUnit(), peer)){ + mpaLayout.put(peer, part); + peersToCheck.remove(key); + break; + } + } + } + for (PeerCard key: mpaLayout.keySet()) { + System.out.println("[DeployStrategyView.buildDefaultInstallationLayout] mpalayout: " + key.getPeerID() + "/" + mpaLayout.get(key).getPartId() ); + } + return mpaLayout; + } + + public static boolean checkDeployementUnit(List<DeploymentUnit> depoyementUnits, PeerCard peer){ + String osUnit; + String pUnit; + for(DeploymentUnit deployementUnit: depoyementUnits){ + //check the existence of: osUnit and platformUnit + if(deployementUnit.getOsUnit()!= null){ + osUnit = deployementUnit.getOsUnit().value(); + if(osUnit == null || osUnit.isEmpty()){ + System.out.println("[DeployStrategyView.checkDeploymentUnit] OSunit is present but not consistent. OSUnit is null or empty"); + return false; + } + //Check if compatible? + if (!osUnit.equals("any")) { + // only considers equal definition + //if (!osUnit.equalsIgnoreCase(peer.getOS())) return false; + System.out.println("osUnit: " + osUnit); + if (!(peer.getOS().contains(osUnit))) return false; + } + }else if (deployementUnit.getPlatformUnit() != null){ + pUnit = deployementUnit.getPlatformUnit().value(); + if(pUnit == null || pUnit.isEmpty()){ + System.out.println("[DeployStrategyView.checkDeploymentUnit] PlatformUnit is present but not consistent. Plaform is null or empty"); + return false; + + } + //check if compatible? + if (!pUnit.equalsIgnoreCase(peer.getPLATFORM_UNIT())) return false; + } + //TODO: check containerUnit? + } + return true; + } + + private void cancel() { + MainWindow.getInstance().removeSubWindow(this); + } + + + +} diff --git a/ucc/ucc.viewjambi/src/main/java/org/universAAL/ucc/viewjambi/install/MpaParser.java b/ucc/ucc.viewjambi/src/main/java/org/universAAL/ucc/viewjambi/install/MpaParser.java new file mode 100644 index 0000000000000000000000000000000000000000..a29b75f82dc7f2f4940761e459854aa86d3a19e5 --- /dev/null +++ b/ucc/ucc.viewjambi/src/main/java/org/universAAL/ucc/viewjambi/install/MpaParser.java @@ -0,0 +1,67 @@ +package org.universAAL.ucc.viewjambi.install; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import javax.xml.bind.*; + +import org.universAAL.middleware.connectors.deploy.model.AalMpa; +import org.universAAL.middleware.connectors.deploy.model.AalMpa.ApplicationPart; +import org.universAAL.middleware.connectors.deploy.model.ObjectFactory; + +public class MpaParser { + AalMpa mpa = null; + + private JAXBContext jc; + private Unmarshaller unmarshaller; + + public MpaParser(String deployPath) { + try { + jc = JAXBContext.newInstance(ObjectFactory.class); + unmarshaller = jc.createUnmarshaller(); + //marshaller = jc.createMarshaller(); + } catch (JAXBException e) { + System.out.println(e); + } + + + File appDir=new File(deployPath); + String[] filelist=appDir.list(); + for(int i=0;i<filelist.length;i++){ + if(filelist[i].endsWith(".mpa")){ + String mpaName = deployPath+File.separator+filelist[i]; + System.out.println("[MpaParser] the mpa file is: " + mpaName); + // convert"\" to "//" -- this is OS dependent, solve later + mpaName = mpaName.replace("\\", "/"); + init(mpaName); + return; + } + } + } + + public void init(String multiPartApplication) { + //get the MPA object representation + System.out.println("[MpaParser.init] multiPartApplication is " + multiPartApplication); + try { + mpa = (AalMpa)unmarshaller.unmarshal(new File(multiPartApplication)); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + if(mpa == null){ + System.out.println("MPA file is not valid. Aborting..."); + return; + } + + } + + public String getAppName() { + return mpa.getApp().getName(); + } + + public ApplicationPart getApplicationPart() { + return mpa.getApplicationPart(); + } +} diff --git a/ucc/ucc.viewjambi/src/main/java/org/universAAL/ucc/viewjambi/juic/Ui_DeployStrategyView.java b/ucc/ucc.viewjambi/src/main/java/org/universAAL/ucc/viewjambi/juic/Ui_DeployStrategyView.java new file mode 100644 index 0000000000000000000000000000000000000000..0162b6e8c8dd544f7594f6ebb18c2cf35d6c65fb --- /dev/null +++ b/ucc/ucc.viewjambi/src/main/java/org/universAAL/ucc/viewjambi/juic/Ui_DeployStrategyView.java @@ -0,0 +1,125 @@ +/******************************************************************************** +** Form generated from reading ui file 'DeployStrategyView.jui' +** +** Created: on 20. jun 15:30:02 2012 +** by: Qt User Interface Compiler version 4.5.2 +** +** WARNING! All changes made in this file will be lost when recompiling ui file! +********************************************************************************/ + +package org.universAAL.ucc.viewjambi.juic; + +import com.trolltech.qt.core.*; +import com.trolltech.qt.gui.*; + +public class Ui_DeployStrategyView implements com.trolltech.qt.QUiForm<QWidget> +{ + public QGridLayout gridLayout_2; + public QGridLayout gridLayout; + public QHBoxLayout horizontalLayout; + public QLabel label_appName; + public QLineEdit lineEdit_appName; + public QLabel label_strategy; + public QVBoxLayout verticalLayout; + public QRadioButton radioButton_all; + public QRadioButton radioButton_selected; + public QHBoxLayout horizontalLayout_2; + public QSpacerItem verticalSpacer; + public QSpacerItem horizontalSpacer_2; + public QPushButton pushButton_ok; + public QPushButton pushButton_cancel; + public QSpacerItem horizontalSpacer; + + public Ui_DeployStrategyView() { super(); } + + public void setupUi(QWidget DeployStrategyView) + { + DeployStrategyView.setObjectName("DeployStrategyView"); + DeployStrategyView.resize(new QSize(301, 157).expandedTo(DeployStrategyView.minimumSizeHint())); + gridLayout_2 = new QGridLayout(DeployStrategyView); + gridLayout_2.setObjectName("gridLayout_2"); + gridLayout = new QGridLayout(); + gridLayout.setObjectName("gridLayout"); + horizontalLayout = new QHBoxLayout(); + horizontalLayout.setObjectName("horizontalLayout"); + label_appName = new QLabel(DeployStrategyView); + label_appName.setObjectName("label_appName"); + + horizontalLayout.addWidget(label_appName); + + lineEdit_appName = new QLineEdit(DeployStrategyView); + lineEdit_appName.setObjectName("lineEdit_appName"); + + horizontalLayout.addWidget(lineEdit_appName); + + + gridLayout.addLayout(horizontalLayout, 0, 0, 1, 2); + + label_strategy = new QLabel(DeployStrategyView); + label_strategy.setObjectName("label_strategy"); + + gridLayout.addWidget(label_strategy, 2, 0, 1, 1); + + verticalLayout = new QVBoxLayout(); + verticalLayout.setObjectName("verticalLayout"); + radioButton_all = new QRadioButton(DeployStrategyView); + radioButton_all.setObjectName("radioButton_all"); + + verticalLayout.addWidget(radioButton_all); + + radioButton_selected = new QRadioButton(DeployStrategyView); + radioButton_selected.setObjectName("radioButton_selected"); + + verticalLayout.addWidget(radioButton_selected); + + + gridLayout.addLayout(verticalLayout, 2, 1, 1, 1); + + horizontalLayout_2 = new QHBoxLayout(); + horizontalLayout_2.setObjectName("horizontalLayout_2"); + verticalSpacer = new QSpacerItem(20, 40, com.trolltech.qt.gui.QSizePolicy.Policy.Minimum, com.trolltech.qt.gui.QSizePolicy.Policy.Expanding); + + horizontalLayout_2.addItem(verticalSpacer); + + horizontalSpacer_2 = new QSpacerItem(40, 20, com.trolltech.qt.gui.QSizePolicy.Policy.Expanding, com.trolltech.qt.gui.QSizePolicy.Policy.Minimum); + + horizontalLayout_2.addItem(horizontalSpacer_2); + + pushButton_ok = new QPushButton(DeployStrategyView); + pushButton_ok.setObjectName("pushButton_ok"); + + horizontalLayout_2.addWidget(pushButton_ok); + + pushButton_cancel = new QPushButton(DeployStrategyView); + pushButton_cancel.setObjectName("pushButton_cancel"); + + horizontalLayout_2.addWidget(pushButton_cancel); + + horizontalSpacer = new QSpacerItem(40, 20, com.trolltech.qt.gui.QSizePolicy.Policy.Expanding, com.trolltech.qt.gui.QSizePolicy.Policy.Minimum); + + horizontalLayout_2.addItem(horizontalSpacer); + + + gridLayout.addLayout(horizontalLayout_2, 5, 0, 1, 2); + + + gridLayout_2.addLayout(gridLayout, 0, 0, 1, 1); + + retranslateUi(DeployStrategyView); + + DeployStrategyView.connectSlotsByName(); + } // setupUi + + void retranslateUi(QWidget DeployStrategyView) + { + DeployStrategyView.setWindowTitle(com.trolltech.qt.core.QCoreApplication.translate("DeployStrategyView", "Select deploy strategy", null)); + label_appName.setText(com.trolltech.qt.core.QCoreApplication.translate("DeployStrategyView", "Application name", null)); + label_strategy.setText(com.trolltech.qt.core.QCoreApplication.translate("DeployStrategyView", "Deploy strategy", null)); + radioButton_all.setText(com.trolltech.qt.core.QCoreApplication.translate("DeployStrategyView", "On all available nodes (default)", null)); + radioButton_selected.setText(com.trolltech.qt.core.QCoreApplication.translate("DeployStrategyView", "On selected nodes", null)); + pushButton_ok.setText(com.trolltech.qt.core.QCoreApplication.translate("DeployStrategyView", "OK", null)); + pushButton_cancel.setText(com.trolltech.qt.core.QCoreApplication.translate("DeployStrategyView", "Cancel", null)); + } // retranslateUi + +} + diff --git a/ucc/ucc.viewjambi/src/main/resources/forms/org/universAAL/ucc/viewjambi/juic/DeployStrategyView.jui b/ucc/ucc.viewjambi/src/main/resources/forms/org/universAAL/ucc/viewjambi/juic/DeployStrategyView.jui new file mode 100644 index 0000000000000000000000000000000000000000..7a19b401ac23b4abd377dcd6cc7d86132a13ec53 --- /dev/null +++ b/ucc/ucc.viewjambi/src/main/resources/forms/org/universAAL/ucc/viewjambi/juic/DeployStrategyView.jui @@ -0,0 +1,121 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0" language="jambi"> + <class>DeployStrategyView</class> + <widget class="QWidget" name="DeployStrategyView"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>301</width> + <height>157</height> + </rect> + </property> + <property name="windowTitle"> + <string>Select deploy strategy</string> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" colspan="2"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label_appName"> + <property name="text"> + <string>Application name</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEdit_appName"/> + </item> + </layout> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_strategy"> + <property name="text"> + <string>Deploy strategy</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QRadioButton" name="radioButton_all"> + <property name="text"> + <string>On all available nodes (default)</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="radioButton_selected"> + <property name="text"> + <string>On selected nodes</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="5" column="0" colspan="2"> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>com.trolltech.qt.core.Qt.Orientation.Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>com.trolltech.qt.core.Qt.Orientation.Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="pushButton_ok"> + <property name="text"> + <string>OK</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_cancel"> + <property name="text"> + <string>Cancel</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>com.trolltech.qt.core.Qt.Orientation.Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui>