Skip to content

Commit

Permalink
Better 501 handling of temporal operations
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed Sep 4, 2023
1 parent 23be467 commit 78e9718
Show file tree
Hide file tree
Showing 18 changed files with 584 additions and 55 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Fixed issues:
* #280 - Changed all error codes from InvalidRequest to BadRequestData, except for JSON Parse Error that is still an InvalidRequest
* #280 - Giving errors for expiresAt in the past (for registrations and subscriptions)
* #280 - Fixed a bug in error detection of downloading errors in arrays of contexts, at lower nesting levels
* #280 - Better 501 handling of temporal operations
69 changes: 37 additions & 32 deletions src/app/orionld/orionldRestServices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
#include "orionld/serviceRoutines/orionldGetContexts.h"
#include "orionld/serviceRoutines/orionldGetVersion.h"
#include "orionld/serviceRoutines/orionldGetPing.h"
#include "orionld/serviceRoutines/orionldNotImplemented.h"
#include "orionld/serviceRoutines/orionldPostBatchUpsert.h"
#include "orionld/serviceRoutines/orionldPostBatchCreate.h"
#include "orionld/serviceRoutines/orionldPostBatchUpdate.h"
Expand All @@ -61,16 +60,22 @@
#include "orionld/serviceRoutines/orionldGetTenants.h"
#include "orionld/serviceRoutines/orionldGetDbIndexes.h"
#include "orionld/serviceRoutines/orionldPostQuery.h"
#include "orionld/serviceRoutines/orionldGetTemporalEntities.h"
#include "orionld/serviceRoutines/orionldGetTemporalEntity.h"
#include "orionld/serviceRoutines/orionldPostTemporalQuery.h"
#include "orionld/serviceRoutines/orionldPostTemporalEntities.h"
#include "orionld/serviceRoutines/orionldPostContexts.h"
#include "orionld/serviceRoutines/orionldDeleteContext.h"
#include "orionld/serviceRoutines/orionldOptions.h"
#include "orionld/serviceRoutines/orionldPutEntity.h"
#include "orionld/serviceRoutines/orionldPutAttribute.h"

#include "orionld/serviceRoutines/orionldGetTemporalEntities.h"
#include "orionld/serviceRoutines/orionldGetTemporalEntity.h"
#include "orionld/serviceRoutines/orionldPostTemporalQuery.h"
#include "orionld/serviceRoutines/orionldPostTemporalEntities.h"
#include "orionld/serviceRoutines/orionldDeleteTemporalAttribute.h" // orionldDeleteTemporalAttribute
#include "orionld/serviceRoutines/orionldDeleteTemporalAttributeInstance.h" // orionldDeleteTemporalAttributeInstance
#include "orionld/serviceRoutines/orionldDeleteTemporalEntity.h" // orionldDeleteTemporalEntity
#include "orionld/serviceRoutines/orionldPatchTemporalAttributeInstance.h" // orionldPatchTemporalAttributeInstance
#include "orionld/serviceRoutines/orionldPostTemporalAttributes.h" // orionldPostTemporalAttributes

#include "orionld/rest/OrionLdRestService.h" // OrionLdRestServiceSimplified
#include "orionld/orionldRestServices.h" // Own Interface

Expand Down Expand Up @@ -111,20 +116,20 @@ static const int getServices = (sizeof(getServiceV) / sizeof(getServiceV[0]));
//
static OrionLdRestServiceSimplified postServiceV[] =
{
{ "/ngsi-ld/v1/entities/*/attrs", orionldPostEntity },
{ "/ngsi-ld/v1/entities", orionldPostEntities },
{ "/ngsi-ld/ex/v1/notify", orionldPostNotify },
{ "/ngsi-ld/v1/entityOperations/create", orionldPostBatchCreate },
{ "/ngsi-ld/v1/entityOperations/upsert", orionldPostBatchUpsert },
{ "/ngsi-ld/v1/entityOperations/update", orionldPostBatchUpdate },
{ "/ngsi-ld/v1/entityOperations/delete", orionldPostBatchDelete },
{ "/ngsi-ld/v1/entityOperations/query", orionldPostQuery },
{ "/ngsi-ld/v1/subscriptions", orionldPostSubscriptions },
{ "/ngsi-ld/v1/csourceRegistrations", orionldPostRegistrations },
{ "/ngsi-ld/v1/temporal/entities/*/attrs", orionldNotImplemented },
{ "/ngsi-ld/v1/temporal/entities", orionldPostTemporalEntities },
{ "/ngsi-ld/v1/temporal/entityOperations/query", orionldPostTemporalQuery },
{ "/ngsi-ld/v1/jsonldContexts", orionldPostContexts }
{ "/ngsi-ld/v1/entities/*/attrs", orionldPostEntity },
{ "/ngsi-ld/v1/entities", orionldPostEntities },
{ "/ngsi-ld/ex/v1/notify", orionldPostNotify },
{ "/ngsi-ld/v1/entityOperations/create", orionldPostBatchCreate },
{ "/ngsi-ld/v1/entityOperations/upsert", orionldPostBatchUpsert },
{ "/ngsi-ld/v1/entityOperations/update", orionldPostBatchUpdate },
{ "/ngsi-ld/v1/entityOperations/delete", orionldPostBatchDelete },
{ "/ngsi-ld/v1/entityOperations/query", orionldPostQuery },
{ "/ngsi-ld/v1/subscriptions", orionldPostSubscriptions },
{ "/ngsi-ld/v1/csourceRegistrations", orionldPostRegistrations },
{ "/ngsi-ld/v1/temporal/entities/*/attrs", orionldPostTemporalAttributes },
{ "/ngsi-ld/v1/temporal/entities", orionldPostTemporalEntities },
{ "/ngsi-ld/v1/temporal/entityOperations/query", orionldPostTemporalQuery },
{ "/ngsi-ld/v1/jsonldContexts", orionldPostContexts }
};
static const int postServices = (sizeof(postServiceV) / sizeof(postServiceV[0]));

Expand All @@ -136,12 +141,12 @@ static const int postServices = (sizeof(postServiceV) / sizeof(postServiceV[0]))
//
static OrionLdRestServiceSimplified patchServiceV[] =
{
{ "/ngsi-ld/v1/entities/*/attrs/*", orionldPatchAttribute },
{ "/ngsi-ld/v1/entities/*/attrs", orionldPatchEntity },
{ "/ngsi-ld/v1/entities/*", orionldPatchEntity2 },
{ "/ngsi-ld/v1/subscriptions/*", orionldPatchSubscription },
{ "/ngsi-ld/v1/csourceRegistrations/*", orionldPatchRegistration },
{ "/ngsi-ld/v1/temporal/entities/*/attrs/*/*", orionldNotImplemented }
{ "/ngsi-ld/v1/entities/*/attrs/*", orionldPatchAttribute },
{ "/ngsi-ld/v1/entities/*/attrs", orionldPatchEntity },
{ "/ngsi-ld/v1/entities/*", orionldPatchEntity2 },
{ "/ngsi-ld/v1/subscriptions/*", orionldPatchSubscription },
{ "/ngsi-ld/v1/csourceRegistrations/*", orionldPatchRegistration },
{ "/ngsi-ld/v1/temporal/entities/*/attrs/*/*", orionldPatchTemporalAttributeInstance }
};
static const int patchServices = (sizeof(patchServiceV) / sizeof(patchServiceV[0]));

Expand All @@ -166,13 +171,13 @@ static const int putServices = (sizeof(putServiceV) / sizeof(putServiceV[0]));
//
static OrionLdRestServiceSimplified deleteServiceV[] =
{
{ "/ngsi-ld/v1/entities/*/attrs/*", orionldDeleteAttribute },
{ "/ngsi-ld/v1/entities/*", orionldDeleteEntity },
{ "/ngsi-ld/v1/subscriptions/*", orionldDeleteSubscription },
{ "/ngsi-ld/v1/csourceRegistrations/*", orionldDeleteRegistration },
{ "/ngsi-ld/v1/jsonldContexts/*", orionldDeleteContext },
{ "/ngsi-ld/v1/temporal/entities/*/attrs/*", orionldNotImplemented },
{ "/ngsi-ld/v1/temporal/entities/*", orionldNotImplemented }
{ "/ngsi-ld/v1/entities/*/attrs/*", orionldDeleteAttribute },
{ "/ngsi-ld/v1/entities/*", orionldDeleteEntity },
{ "/ngsi-ld/v1/subscriptions/*", orionldDeleteSubscription },
{ "/ngsi-ld/v1/csourceRegistrations/*", orionldDeleteRegistration },
{ "/ngsi-ld/v1/jsonldContexts/*", orionldDeleteContext },
{ "/ngsi-ld/v1/temporal/entities/*/attrs/*", orionldDeleteTemporalAttribute },
{ "/ngsi-ld/v1/temporal/entities/*", orionldDeleteTemporalEntity },
};
static const int deleteServices = (sizeof(deleteServiceV) / sizeof(deleteServiceV[0]));

Expand Down
2 changes: 2 additions & 0 deletions src/lib/orionld/rest/OrionLdRestService.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ typedef struct OrionLdRestService
uint32_t options; // Peculiarities of this type of requests (bitmask)
uint64_t uriParams; // Supported URI parameters (bitmask)
bool isBatchOp; // true for BATCH operations
bool notImplemented; // Flags that the service hasn't been implemented
bool mintaka; // Flags that the service is not for Orion-LD but for Mintaka
} OrionLdRestService;


Expand Down
7 changes: 7 additions & 0 deletions src/lib/orionld/rest/orionldMhdConnectionInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,13 @@ MHD_Result orionldMhdConnectionInit
if (orionldState.serviceP == NULL) // 405 or 404 - no need to continue - prettyPrint not possible here
return MHD_YES;

if (orionldState.serviceP->mintaka == true)
return MHD_YES;

if (orionldState.serviceP->notImplemented == true)
return MHD_YES;


//
// 5. GET URI params
//
Expand Down
15 changes: 15 additions & 0 deletions src/lib/orionld/rest/orionldMhdConnectionTreat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,21 @@ MHD_Result orionldMhdConnectionTreat(void)

promCounterIncrease(promNgsildRequests);

if (orionldState.serviceP == NULL)
goto respond;

if (orionldState.serviceP->mintaka == true)
{
serviceRoutineResult = orionldState.serviceP->serviceRoutine();
goto respond;
}

if (orionldState.serviceP->notImplemented == true)
{
serviceRoutineResult = orionldState.serviceP->serviceRoutine();
goto respond;
}

// If OPTIONS verb, we skip all checks, go straight to the service routine
if (orionldState.verb == OPTIONS)
goto serviceRoutine;
Expand Down
30 changes: 29 additions & 1 deletion src/lib/orionld/rest/orionldServiceInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,23 @@
#include "orionld/serviceRoutines/orionldGetEntityType.h" // orionldGetEntityType
#include "orionld/serviceRoutines/orionldGetEntityAttributes.h" // orionldGetEntityAttributes
#include "orionld/serviceRoutines/orionldGetEntityAttribute.h" // orionldGetEntityAttribute
#include "orionld/serviceRoutines/orionldPostTemporalEntities.h" // orionldPostTemporalEntities

#include "orionld/serviceRoutines/orionldGetContexts.h" // orionldGetContexts
#include "orionld/serviceRoutines/orionldGetContext.h" // orionldGetContext
#include "orionld/serviceRoutines/orionldPostContexts.h" // orionldPostContexts
#include "orionld/serviceRoutines/orionldDeleteContext.h" // orionldDeleteContext
#include "orionld/serviceRoutines/orionldPostNotify.h" // orionldPostNotify

#include "orionld/serviceRoutines/orionldGetTemporalEntities.h" // orionldGetTemporalEntities
#include "orionld/serviceRoutines/orionldGetTemporalEntity.h" // orionldGetTemporalEntity
#include "orionld/serviceRoutines/orionldPostTemporalQuery.h" // orionldPostTemporalQuery
#include "orionld/serviceRoutines/orionldPostTemporalEntities.h" // orionldPostTemporalEntities
#include "orionld/serviceRoutines/orionldDeleteTemporalAttribute.h" // orionldDeleteTemporalAttribute
#include "orionld/serviceRoutines/orionldDeleteTemporalAttributeInstance.h" // orionldDeleteTemporalAttributeInstance
#include "orionld/serviceRoutines/orionldDeleteTemporalEntity.h" // orionldDeleteTemporalEntity
#include "orionld/serviceRoutines/orionldPatchTemporalAttributeInstance.h" // orionldPatchTemporalAttributeInstance
#include "orionld/serviceRoutines/orionldPostTemporalAttributes.h" // orionldPostTemporalAttributes

#include "orionld/troe/troePostEntities.h" // troePostEntities
#include "orionld/troe/troePostBatchDelete.h" // troePostBatchDelete
#include "orionld/troe/troeDeleteAttribute.h" // troeDeleteAttribute
Expand Down Expand Up @@ -403,6 +413,24 @@ static void restServicePrepare(OrionLdRestService* serviceP, OrionLdRestServiceS
serviceP->options |= ORIONLD_SERVICE_OPTION_PREFETCH_ID_AND_TYPE;
serviceP->options |= ORIONLD_SERVICE_OPTION_EXPAND_TYPE;
}
else if (serviceP->serviceRoutine == orionldGetTemporalEntities)
serviceP->mintaka = true;
else if (serviceP->serviceRoutine == orionldGetTemporalEntity)
serviceP->mintaka = true;
else if (serviceP->serviceRoutine == orionldPostTemporalQuery)
serviceP->mintaka = true;
else if (serviceP->serviceRoutine == orionldDeleteTemporalAttribute)
serviceP->notImplemented = true;
else if (serviceP->serviceRoutine == orionldDeleteTemporalAttributeInstance)
serviceP->notImplemented = true;
else if (serviceP->serviceRoutine == orionldDeleteTemporalEntity)
serviceP->notImplemented = true;
else if (serviceP->serviceRoutine == orionldPatchTemporalAttributeInstance)
serviceP->notImplemented = true;
else if (serviceP->serviceRoutine == orionldPostTemporalAttributes)
serviceP->notImplemented = true;


else if (serviceP->serviceRoutine == orionldGetVersion)
{
serviceP->options = 0; // Tenant is Ignored
Expand Down
6 changes: 5 additions & 1 deletion src/lib/orionld/serviceRoutines/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ SET (SOURCES
orionldGetContext.cpp
orionldGetContexts.cpp
orionldGetVersion.cpp
orionldNotImplemented.cpp
orionldPostBatchCreate.cpp
orionldPostBatchUpsert.cpp
orionldPostBatchUpdate.cpp
Expand All @@ -67,6 +66,11 @@ SET (SOURCES
orionldOptions.cpp
orionldPutEntity.cpp
orionldPutAttribute.cpp
orionldDeleteTemporalAttribute.cpp
orionldDeleteTemporalAttributeInstance.cpp
orionldDeleteTemporalEntity.cpp
orionldPatchTemporalAttributeInstance.cpp
orionldPostTemporalAttributes.cpp
)

# Include directories
Expand Down
43 changes: 43 additions & 0 deletions src/lib/orionld/serviceRoutines/orionldDeleteTemporalAttribute.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
*
* Copyright 2023 FIWARE Foundation e.V.
*
* This file is part of Orion-LD Context Broker.
*
* Orion-LD Context Broker is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Orion-LD Context Broker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by this license please contact with
* orionld at fiware dot org
*
* Author: Ken Zangelin
*/
#include "logMsg/logMsg.h"

#include "orionld/common/orionldState.h" // orionldState
#include "orionld/common/orionldError.h" // orionldError
#include "orionld/rest/OrionLdRestService.h" // OrionLdRestService
#include "orionld/serviceRoutines/orionldDeleteTemporalAttribute.h" // Own Interface



// ----------------------------------------------------------------------------
//
// orionldDeleteTemporalAttribute -
//
bool orionldDeleteTemporalAttribute(void)
{
orionldError(OrionldOperationNotSupported, "Not Implemented", orionldState.serviceP->url, 501);
orionldState.noLinkHeader = true; // We don't want the Link header for non-implemented requests
return false;
}
37 changes: 37 additions & 0 deletions src/lib/orionld/serviceRoutines/orionldDeleteTemporalAttribute.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef SRC_LIB_ORIONLD_SERVICEROUTINES_ORIONLDDELETETEMPORALATTRIBUTE_H_
#define SRC_LIB_ORIONLD_SERVICEROUTINES_ORIONLDDELETETEMPORALATTRIBUTE_H_

/*
*
* Copyright 2023 FIWARE Foundation e.V.
*
* This file is part of Orion-LD Context Broker.
*
* Orion-LD Context Broker is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Orion-LD Context Broker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by this license please contact with
* orionld at fiware dot org
*
* Author: Ken Zangelin
*/



// ----------------------------------------------------------------------------
//
// orionldDeleteTemporalAttribute -
//
extern bool orionldDeleteTemporalAttribute(void);

#endif // SRC_LIB_ORIONLD_SERVICEROUTINES_ORIONLDDELETETEMPORALATTRIBUTE_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
*
* Copyright 2023 FIWARE Foundation e.V.
*
* This file is part of Orion-LD Context Broker.
*
* Orion-LD Context Broker is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Orion-LD Context Broker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by this license please contact with
* orionld at fiware dot org
*
* Author: Ken Zangelin
*/
#include "logMsg/logMsg.h"

#include "orionld/common/orionldState.h" // orionldState
#include "orionld/common/orionldError.h" // orionldError
#include "orionld/rest/OrionLdRestService.h" // OrionLdRestService
#include "orionld/serviceRoutines/orionldDeleteTemporalAttributeInstance.h" // Own Interface



// ----------------------------------------------------------------------------
//
// orionldDeleteTemporalAttributeInstance -
//
bool orionldDeleteTemporalAttributeInstance(void)
{
orionldError(OrionldOperationNotSupported, "Not Implemented", orionldState.serviceP->url, 501);
orionldState.noLinkHeader = true; // We don't want the Link header for non-implemented requests
return false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef SRC_LIB_ORIONLD_SERVICEROUTINES_ORIONLDDELETETEMPORALATTRIBUTEINSTANCE_H_
#define SRC_LIB_ORIONLD_SERVICEROUTINES_ORIONLDDELETETEMPORALATTRIBUTEINSTANCE_H_

/*
*
* Copyright 2023 FIWARE Foundation e.V.
*
* This file is part of Orion-LD Context Broker.
*
* Orion-LD Context Broker is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Orion-LD Context Broker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by this license please contact with
* orionld at fiware dot org
*
* Author: Ken Zangelin
*/



// ----------------------------------------------------------------------------
//
// orionldDeleteTemporalAttributeInstance -
//
extern bool orionldDeleteTemporalAttributeInstance(void);

#endif // SRC_LIB_ORIONLD_SERVICEROUTINES_ORIONLDDELETETEMPORALATTRIBUTEINSTANCE_H_
Loading

0 comments on commit 78e9718

Please sign in to comment.