def fetch(self, vnfPkgId, artifactPath):
logger.debug("FetchVnfPkgArtifact--get--single--artifact--biz::>"
"ID: %s path: %s" % (vnfPkgId, artifactPath))
- vnf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnfPkgId).get()
- if not vnf_pkg:
+ vnf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnfPkgId)
+ if not vnf_pkg.exists():
err_msg = "NF Package (%s) doesn't exists." % vnfPkgId
- return ResourceNotFoundException(err_msg)
+ raise ResourceNotFoundException(err_msg)
+ vnf_pkg = vnf_pkg.get()
local_path = vnf_pkg.localFilePath
if local_path.endswith(".csar") or local_path.endswith(".zip"):
vnf_extract_path = fileutil.unzip_csar_to_tmp(local_path)
from catalog.pub.exceptions import NsdmBadRequestException
from catalog.pub.exceptions import PackageNotFoundException
from catalog.pub.exceptions import ResourceNotFoundException
+from catalog.pub.exceptions import ArtifactNotFoundException
logger = logging.getLogger(__name__)
detail=e.message,
status=status.HTTP_404_NOT_FOUND
)
+ except ArtifactNotFoundException as e:
+ logger.error(e.message)
+ return make_error_resp(
+ detail=e.message,
+ status=status.HTTP_404_NOT_FOUND
+ )
except NsdmBadRequestException as e:
logger.error(e.message)
return make_error_resp(
# See the License for the specific language governing permissions and
# limitations under the License.
-
-import traceback
import logging
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
from rest_framework.views import APIView
-from rest_framework.response import Response
from django.http import FileResponse
from catalog.packages.serializers.response import ProblemDetailsSerializer
from catalog.packages.biz.vnf_pkg_artifacts import FetchVnfPkgArtifact
-from catalog.pub.exceptions import ResourceNotFoundException, ArtifactNotFoundException
+from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
-VALID_FILTERS = ["callbackUri", "notificationTypes", "vnfdId", "vnfPkgId", "operationalState", "usageState"]
-
-def get_problem_details_serializer(status_code, error_message):
- problem_details = {
- "status": status_code,
- "detail": error_message
- }
- problem_details_serializer = ProblemDetailsSerializer(data=problem_details)
- problem_details_serializer.is_valid()
- return problem_details_serializer
+VALID_FILTERS = [
+ "callbackUri",
+ "notificationTypes",
+ "vnfdId",
+ "vnfPkgId",
+ "operationalState",
+ "usageState"
+]
class FetchVnfPkgmArtifactsView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
+ @view_safe_call_with_log(logger=logger)
def get(self, request, vnfPkgId, artifactPath):
logger.debug("FetchVnfPkgmArtifactsView--get::> ")
- try:
- resp_data = FetchVnfPkgArtifact().fetch(vnfPkgId, artifactPath)
- response = FileResponse(resp_data)
+ resp_data = FetchVnfPkgArtifact().fetch(vnfPkgId, artifactPath)
+ response = FileResponse(resp_data)
- return response
- except ResourceNotFoundException as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- problem_details_serializer = get_problem_details_serializer(status.HTTP_404_NOT_FOUND,
- traceback.format_exc())
- return Response(data=problem_details_serializer.data, status=status.HTTP_404_NOT_FOUND)
- except ArtifactNotFoundException as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- problem_details_serializer = get_problem_details_serializer(status.HTTP_404_NOT_FOUND,
- traceback.format_exc())
- return Response(data=problem_details_serializer.data, status=status.HTTP_404_NOT_FOUND)
- except Exception as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- problem_details_serializer = get_problem_details_serializer(status.HTTP_404_NOT_FOUND,
- traceback.format_exc())
- return Response(data=problem_details_serializer.data, status=status.HTTP_404_NOT_FOUND)
+ return response