use of org.eclipse.kura.core.deployment.xml.XmlBundleInfo 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.XmlBundleInfo 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.XmlBundleInfo 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.XmlBundleInfo in project kura by eclipse.
the class XmlJavaPackagesMapper method marshalDeploymentPackage.
//
// Marshaller's private methods
//
private static void marshalDeploymentPackage(Document doc, XmlDeploymentPackage xdp, Element packageInstalled) {
// Extract data from XmlDeploymentPackage
String packageName = xdp.getName();
String packageVersion = xdp.getVersion();
XmlBundleInfo[] xbiArray = xdp.getBundleInfos();
// Create xml elements
if (packageName != null && !packageName.trim().isEmpty()) {
Element name = doc.createElement(PACKAGES_PACKAGE_NAME);
name.setTextContent(packageName);
packageInstalled.appendChild(name);
}
if (packageVersion != null && !packageVersion.trim().isEmpty()) {
Element version = doc.createElement(PACKAGES_PACKAGE_VERSION);
version.setTextContent(packageVersion);
packageInstalled.appendChild(version);
}
Element bundles = doc.createElement(PACKAGES_PACKAGE_BUNDLES);
packageInstalled.appendChild(bundles);
if (xbiArray != null) {
for (XmlBundleInfo xbi : xbiArray) {
Element bundle = doc.createElement(PACKAGES_PACKAGE_BUNDLES_BUNDLE);
marshalBundleInfo(doc, xbi, bundle);
bundles.appendChild(bundle);
}
}
}
use of org.eclipse.kura.core.deployment.xml.XmlBundleInfo in project kura by eclipse.
the class CoreTestXmlUtil method parseBundles.
private static XmlBundleInfo[] parseBundles(Node node) {
List<XmlBundleInfo> bundleInfos = new ArrayList<XmlBundleInfo>();
NodeList nodeList = node.getChildNodes();
// Get information for each bundle
for (int i = 0; i < nodeList.getLength(); i++) {
Node bundleNode = nodeList.item(i);
if (bundleNode.getNodeType() == Node.ELEMENT_NODE) {
XmlBundleInfo xbi = new XmlBundleInfo();
NodeList infoList = bundleNode.getChildNodes();
for (int j = 0; j < infoList.getLength(); j++) {
Node tmpNode = infoList.item(j);
// Set Bundle Name
if (tmpNode.getNodeName().equals("name"))
xbi.setName(tmpNode.getTextContent());
else // Set Bundle Version
if (tmpNode.getNodeName().equals("version"))
xbi.setVersion(tmpNode.getTextContent());
}
// Add bundle to array
bundleInfos.add(xbi);
}
}
return bundleInfos.toArray(new XmlBundleInfo[bundleInfos.size()]);
}
Aggregations