use of org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage in project kura by eclipse.
the class CloudDeploymentHandlerV2 method doGetPackages.
private void doGetPackages(KuraResponsePayload response) {
DeploymentPackage[] dps = this.m_deploymentAdmin.listDeploymentPackages();
XmlDeploymentPackages xdps = new XmlDeploymentPackages();
XmlDeploymentPackage[] axdp = new XmlDeploymentPackage[dps.length];
for (int i = 0; i < dps.length; i++) {
DeploymentPackage dp = dps[i];
XmlDeploymentPackage xdp = new XmlDeploymentPackage();
xdp.setName(dp.getName());
xdp.setVersion(dp.getVersion().toString());
BundleInfo[] bis = dp.getBundleInfos();
XmlBundleInfo[] axbi = new XmlBundleInfo[bis.length];
for (int j = 0; j < bis.length; j++) {
BundleInfo bi = bis[j];
XmlBundleInfo xbi = new XmlBundleInfo();
xbi.setName(bi.getSymbolicName());
xbi.setVersion(bi.getVersion().toString());
axbi[j] = xbi;
}
xdp.setBundleInfos(axbi);
axdp[i] = xdp;
}
xdps.setDeploymentPackages(axdp);
try {
String s = XmlUtil.marshal(xdps);
response.setTimestamp(new Date());
response.setBody(s.getBytes("UTF-8"));
} catch (Exception e) {
s_logger.error("Error getting resource {}: {}", RESOURCE_PACKAGES, e);
}
}
use of org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage in project kura by eclipse.
the class XmlUtilTest method getSampleXmlDeploymentPackagesObject.
private static XmlDeploymentPackages getSampleXmlDeploymentPackagesObject() {
XmlDeploymentPackages xmlDeploymentPackages = new XmlDeploymentPackages();
XmlBundleInfo inputXmlBundleInfo = new XmlBundleInfo();
inputXmlBundleInfo.setName("XmlBundleInfo");
inputXmlBundleInfo.setVersion("3.0.1.201");
XmlDeploymentPackage inputXmlDeploymentPackage = new XmlDeploymentPackage();
inputXmlDeploymentPackage.setName("raspberry");
inputXmlDeploymentPackage.setVersion("3.0.1");
inputXmlDeploymentPackage.setBundleInfos(new XmlBundleInfo[] { inputXmlBundleInfo });
xmlDeploymentPackages.setDeploymentPackages(new XmlDeploymentPackage[] { inputXmlDeploymentPackage });
return xmlDeploymentPackages;
}
use of org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage in project kura by eclipse.
the class CloudDeploymentHandlerTest method testGetPackages.
@TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL })
@Test
@Ignore
public void testGetPackages() throws Exception {
assertTrue(s_cloudCallService.isConnected());
DeploymentPackage dp = s_deploymentAdmin.getDeploymentPackage(LOCAL_DP_NAME);
if (dp == null) {
s_logger.warn("Getting dp");
InputStream is = getTestDpUrl().openStream();
dp = s_deploymentAdmin.installDeploymentPackage(is);
}
StringBuilder sb = new StringBuilder(CloudletTopic.Method.GET.toString()).append("/").append(CloudDeploymentHandlerV2.RESOURCE_PACKAGES);
KuraResponsePayload resp = s_cloudCallService.call(CloudDeploymentHandlerV2.APP_ID, sb.toString(), null, 5000);
assertEquals(KuraResponsePayload.RESPONSE_CODE_OK, resp.getResponseCode());
String s = new String(resp.getBody());
// XmlDeploymentPackages xmlPackages = XmlUtil.unmarshal(s, XmlDeploymentPackages.class);
XmlDeploymentPackages xmlPackages = CoreTestXmlUtil.unmarshal(s, XmlDeploymentPackages.class);
XmlDeploymentPackage[] packages = xmlPackages.getDeploymentPackages();
XmlDeploymentPackage xmlDp = null;
if (packages != null) {
for (int i = 0; i < packages.length; i++) {
if (packages[i].getName().equals(LOCAL_DP_NAME)) {
xmlDp = packages[i];
break;
}
}
}
assertNotNull(xmlDp);
assertEquals(LOCAL_DP_VERSION, xmlDp.getVersion());
XmlBundleInfo[] bundleInfos = xmlDp.getBundleInfos();
assertEquals(1, bundleInfos.length);
assertEquals(LOCAL_BUNDLE_NAME, bundleInfos[0].getName());
assertEquals(LOCAL_BUNDLE_VERSION, bundleInfos[0].getVersion());
}
use of org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage in project kura by eclipse.
the class CoreTestXmlUtil method unmarshalXmlDeploymentPackages.
// unmarshal XmlDeploymentPackages
@SuppressWarnings("unchecked")
public static <T> T unmarshalXmlDeploymentPackages(Document doc) throws Exception {
// Java objects for unmarshal
XmlDeploymentPackages xmlDeploymentPackages = new XmlDeploymentPackages();
List<XmlDeploymentPackage> xmlDeploymentPackageList = new ArrayList<XmlDeploymentPackage>();
// XML elements
Element packages = doc.getDocumentElement();
NodeList packagesChildren = packages.getChildNodes();
// Collect all packages
for (int propIndex = 0; propIndex < packagesChildren.getLength(); propIndex++) {
Node currentNode = packagesChildren.item(propIndex);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
Element el = (Element) currentNode;
if (el.getNodeName().equals("package")) {
XmlDeploymentPackage xdp = new XmlDeploymentPackage();
NodeList nodeList = el.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node tmpNode = nodeList.item(i);
// Set package name
if (tmpNode.getNodeName().equals("name"))
xdp.setName(tmpNode.getTextContent());
else // Set package version
if (tmpNode.getNodeName().equals("version"))
xdp.setVersion(tmpNode.getTextContent());
else // Set bundle info
if (tmpNode.getNodeName().equals("bundles"))
xdp.setBundleInfos(parseBundles(tmpNode));
}
xmlDeploymentPackageList.add(xdp);
}
}
}
// Add packages
xmlDeploymentPackages.setDeploymentPackages(xmlDeploymentPackageList.toArray(new XmlDeploymentPackage[xmlDeploymentPackageList.size()]));
return (T) xmlDeploymentPackages;
}
use of org.eclipse.kura.core.deployment.xml.XmlDeploymentPackage in project kura by eclipse.
the class XmlJavaPackagesMapper method marshal.
@Override
public Element marshal(Document doc, Object object) throws Exception {
Element packages = doc.createElement(PACKAGES);
doc.appendChild(packages);
XmlDeploymentPackages xdps = (XmlDeploymentPackages) object;
XmlDeploymentPackage[] xdpArray = xdps.getDeploymentPackages();
for (XmlDeploymentPackage xdp : xdpArray) {
Element packageInstalled = doc.createElement(PACKAGES_PACKAGE);
marshalDeploymentPackage(doc, xdp, packageInstalled);
packages.appendChild(packageInstalled);
}
return packages;
}
Aggregations