ONU SW upgrade API change - step 2: added Abort and Get_onu_image_status functionality

Signed-off-by: mpagenko <michael.pagenkopf@adtran.com>
Change-Id: I577442affd3f63f429367e012a67184429359f94
diff --git a/internal/pkg/onuadaptercore/file_download_manager.go b/internal/pkg/onuadaptercore/file_download_manager.go
index 0658c6f..1dfd50a 100644
--- a/internal/pkg/onuadaptercore/file_download_manager.go
+++ b/internal/pkg/onuadaptercore/file_download_manager.go
@@ -29,6 +29,7 @@
 	"time"
 
 	"github.com/opencord/voltha-lib-go/v4/pkg/log"
+	"github.com/opencord/voltha-protos/v4/go/voltha"
 )
 
 const cDefaultLocalDir = "/tmp" //this is the default local dir to download to
@@ -348,3 +349,48 @@
 	}()
 	return nil
 }
+
+func (dm *fileDownloadManager) RequestDownloadState(ctx context.Context, aImageName string,
+	apDlToAdapterImageState *voltha.ImageState) {
+	logger.Debugw(ctx, "request download state for image to Adapter", log.Fields{"image-name": aImageName})
+	dm.mutexDownloadImageDsc.RLock()
+	defer dm.mutexDownloadImageDsc.RUnlock()
+
+	for _, dnldImgDsc := range dm.downloadImageDscSlice {
+		if dnldImgDsc.downloadImageName == aImageName {
+			//image found (by name)
+			apDlToAdapterImageState.DownloadState = voltha.ImageState_DOWNLOAD_REQUESTED
+			apDlToAdapterImageState.Reason = voltha.ImageState_NO_ERROR
+			return
+		}
+	}
+	//image not found (by name)
+	apDlToAdapterImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN
+	apDlToAdapterImageState.Reason = voltha.ImageState_NO_ERROR
+}
+
+func (dm *fileDownloadManager) CancelDownload(ctx context.Context, aImageName string) {
+	logger.Debugw(ctx, "Cancel the download to Adapter", log.Fields{"image-name": aImageName})
+	// for the moment that would only support to wait for the download end and remove the image then
+	//   further reactions while still downloading can be considered with some effort, but does it make sense (synchronous load here!)
+	dm.mutexDownloadImageDsc.RLock()
+	defer dm.mutexDownloadImageDsc.RUnlock()
+
+	tmpSlice := dm.downloadImageDscSlice[:0]
+	for _, dnldImgDsc := range dm.downloadImageDscSlice {
+		if dnldImgDsc.downloadImageName == aImageName {
+			//image found (by name) - remove the image from filesystem
+			logger.Debugw(ctx, "removing image", log.Fields{"image-name": aImageName})
+			aLocalPathName := cDefaultLocalDir + "/" + aImageName
+			if err := os.Remove(aLocalPathName); err != nil {
+				logger.Debugw(ctx, "image not removed from filesystem", log.Fields{
+					"image-name": aImageName, "error": err})
+			}
+			// and in the imageDsc slice by just not appending
+		} else {
+			tmpSlice = append(tmpSlice, dnldImgDsc)
+		}
+	}
+	dm.downloadImageDscSlice = tmpSlice
+	//image not found (by name)
+}