package org.onap.policy.distribution.reception.handling.sdc;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
-import java.util.Map;
+import java.lang.reflect.Type;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.distribution.model.CloudArtifact;
import org.onap.policy.distribution.model.Csar;
import org.onap.policy.distribution.model.GsonUtil;
-import org.onap.policy.distribution.model.VfModuelModel;
+import org.onap.policy.distribution.model.VfModuleModel;
import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler;
import org.onap.policy.distribution.reception.handling.sdc.SdcClientHandler.SdcClientOperationType;
*/
public void processVfModulesArtifacts(final INotificationData notificationData, IResourceInstance resource) {
boolean artifactsProcessedSuccessfully = true;
+ LOGGER.debug("start process VF MODULES_METADATA: " );
DistributionStatisticsManager.updateTotalDistributionCount();
List<String> relevantArtifactTypes = sdcConfig.getRelevantArtifactTypes();
Path path = Paths.get("/data");
- List<VfModuelModel> vfModuelModels = null;
- Map<String, String> artifactTypeMap = null; //key is UUID, value is type for k8s plugin
- Map<String, IArtifactInfo> artifactMap = null;//key is UUID, value is artifact for shared folder
+ ArrayList<VfModuleModel> vfModuleModels = new ArrayList<>();
+ HashMap<String, IArtifactInfo> artifactMap = new HashMap<>();//key is UUID, value is artifact for shared folder
String vfArtifactData = null;
+ IArtifactInfo vfModuleMetaDataArtifact = null;
for (final IArtifactInfo artifact : resource.getArtifacts()) {
- artifactTypeMap.put(artifact.getArtifactUUID(),artifact.getArtifactType());
artifactMap.put(artifact.getArtifactUUID(),artifact);
- //extract the artifactlist and write them into MongoDB
+ //extract the artifactlist and write them into MongoDB
if (artifact.getArtifactType().equals("VF_MODULES_METADATA")) {
try {
final IDistributionClientDownloadResult resultArtifact =
downloadTheArtifact(artifact,notificationData);
- vfArtifactData = new String(resultArtifact.getArtifactPayload());
- vfModuelModels= GsonUtil.parseJsonArrayWithGson(vfArtifactData,VfModuelModel.class);
- } catch (final ArtifactDownloadException exp) {
- LOGGER.error("Failed to process csar service artifacts ", exp);
+ if (resultArtifact != null) {
+ vfArtifactData = new String(resultArtifact.getArtifactPayload(),"UTF-8");
+ LOGGER.debug("VF_MODULE_ARTIFACT: " + new String(resultArtifact.getArtifactPayload(),"UTF-8"));
+ }
+ Type listType = new TypeToken<ArrayList<VfModuleModel>>(){}.getType();
+ vfModuleModels = new Gson().fromJson(vfArtifactData,listType);
+ LOGGER.debug("pass to process VF_MODULES_METADATA artifacts ");
+ vfModuleMetaDataArtifact = artifact;
+ } catch (final ArtifactDownloadException | UnsupportedEncodingException exp) {
+ LOGGER.error("Failed to process csar VF_MODULES_METADATA artifacts ", exp);
artifactsProcessedSuccessfully = false;
sendDistributionStatus(DistributionStatusType.DEPLOY, artifact.getArtifactURL(),
notificationData.getDistributionID(), DistributionStatusEnum.DEPLOY_ERROR,
// 2. put the vfmodule-meta.json into it
// 3. put the service-meta.json into it
// 3. go through each aritfact uuid under artifact_list of vf_module and download
- for (final VfModuelModel vfModule : vfModuelModels) {
+ for (final VfModuleModel vfModule : vfModuleModels) {
try {
//create the new dir
Path temp = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID());
path = Files.createDirectory(temp);//create UUID path
//store the value to vfmodule-meta.json
- String filePath = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID(),"vfmodule-meta.json").toString();
+ String filePath = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID(),
+ "vfmodule-meta.json").toString();
writeFileByFileWriter(filePath, vfArtifactData);
//store the service level info to serivce-meta.json
- filePath = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID(),"service-meta.json").toString();
+ filePath = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID(),
+ "service-meta.json").toString();
writeFileByFileWriter(filePath, notificationData.toString());
+ LOGGER.debug("pass to create directory artifact file");
} catch (final IOException exp) {
LOGGER.error("Failed to create directory artifact file", exp);
}
- for(final String uuid : vfModule.getArtifacts()) {
+ for (final String uuid : vfModule.getArtifacts()) {
try {
IArtifactInfo artifact = artifactMap.get(uuid);
final IDistributionClientDownloadResult resultArtifact = downloadTheArtifact(artifact, notificationData);
writeArtifactToDir(artifact,resultArtifact,path);
+ LOGGER.debug("pass to write Artifact to dir ");
} catch (final ArtifactDownloadException exp) {
- LOGGER.error("Failed to process csar service artifacts ", exp);
+ LOGGER.error("Failed to write artifact to dir ", exp);
artifactsProcessedSuccessfully = false;
sendDistributionStatus(DistributionStatusType.DEPLOY, artifactMap.get(uuid).getArtifactURL(),
notificationData.getDistributionID(), DistributionStatusEnum.DEPLOY_ERROR,
//for subplug work
try {
- final CloudArtifact cloudArtifact = new CloudArtifact(vfModuelModels, artifactTypeMap);
+ final CloudArtifact cloudArtifact = new CloudArtifact(vfModuleModels, artifactMap);
inputReceived(cloudArtifact);
+ LOGGER.debug("pass to process cloud artifacts ");
} catch ( final PolicyDecodingException exp) {
LOGGER.error("Failed to process cloud artifacts ", exp);
artifactsProcessedSuccessfully = false;
DistributionStatisticsManager.updateDistributionSuccessCount();
sendComponentDoneStatus(notificationData.getDistributionID(), DistributionStatusEnum.COMPONENT_DONE_OK,
null);
+ if (vfModuleMetaDataArtifact != null) {
+ LOGGER.debug("one vfModuleMetaDataArtifact found" );
+ sendDistributionStatus(DistributionStatusType.DEPLOY, vfModuleMetaDataArtifact.getArtifactURL(),
+ notificationData.getDistributionID(), DistributionStatusEnum.DEPLOY_OK, null);
+ } else {
+ LOGGER.debug("no vfModuleMetaDataArtifact found" );
+ }
+
} else {
DistributionStatisticsManager.updateDistributionFailureCount();
sendComponentDoneStatus(notificationData.getDistributionID(), DistributionStatusEnum.COMPONENT_DONE_ERROR,
"Failed to process the artifact");
}
+ LOGGER.debug("end process VF MODULES_METADATA: " );
}
/**
private static void writeFileByFileWriter(String filePath, String content) throws IOException {
File file = new File(filePath);
synchronized (file) {
- FileWriter fw = new FileWriter(filePath);
- fw.write(content);
- fw.close();
+ try (FileWriter fw = new FileWriter(filePath)) {
+ fw.write(content);
+ } catch (final IOException exp) {
+ LOGGER.error("Failed to write File by File Writer ", exp);
+ }
}
}
/**