Skip to content
Snippets Groups Projects
Commit 1af2c37f authored by Sergey Yakubov's avatar Sergey Yakubov
Browse files

use service unavailable error

parent d5dcac15
No related branches found
No related tags found
No related merge requests found
...@@ -225,7 +225,7 @@ var authTests = []struct { ...@@ -225,7 +225,7 @@ var authTests = []struct {
`{"beamtimeId":"test_online","beamline":"bl1","dataSource":"dataSource","corePath":"./tf/gpfs/bl1/2019/data/test_online","beamline-path":"./bl1/current","source-type":"raw","access-types":["read","write","writeraw"]}`, 0}, `{"beamtimeId":"test_online","beamline":"bl1","dataSource":"dataSource","corePath":"./tf/gpfs/bl1/2019/data/test_online","beamline-path":"./bl1/current","source-type":"raw","access-types":["read","write","writeraw"]}`, 0},
{"raw", "auto", "p07", "dataSource", "", "127.0.0.1", http.StatusOK, "raw type, auto beamtime", {"raw", "auto", "p07", "dataSource", "", "127.0.0.1", http.StatusOK, "raw type, auto beamtime",
`{"beamtimeId":"11111111","beamline":"p07","dataSource":"dataSource","corePath":"asap3/petra3/gpfs/p07/2020/data/11111111","beamline-path":"./p07/current","source-type":"raw","access-types":["read","write","writeraw"]}`, 0}, `{"beamtimeId":"11111111","beamline":"p07","dataSource":"dataSource","corePath":"asap3/petra3/gpfs/p07/2020/data/11111111","beamline-path":"./p07/current","source-type":"raw","access-types":["read","write","writeraw"]}`, 0},
{"raw", "auto", "p07", "noldap", "", "127.0.0.1", http.StatusNotFound, "no conection to ldap", {"raw", "auto", "p07", "noldap", "", "127.0.0.1", http.StatusServiceUnavailable, "no conection to ldap",
"", 0}, "", 0},
{"raw", "auto", "p07", "dataSource", prepareAsapoToken("bl_p07", []string{"read", "writeraw"}), "127.0.0.2", http.StatusOK, "raw type with token", {"raw", "auto", "p07", "dataSource", prepareAsapoToken("bl_p07", []string{"read", "writeraw"}), "127.0.0.2", http.StatusOK, "raw type with token",
......
...@@ -12,8 +12,8 @@ import ( ...@@ -12,8 +12,8 @@ import (
"asapo_common/version" "asapo_common/version"
"errors" "errors"
"net/http" "net/http"
"strconv"
_ "net/http/pprof" _ "net/http/pprof"
"strconv"
) )
func Start() { func Start() {
......
...@@ -87,6 +87,8 @@ func (a *AsapoAuthorizer) doRequest(req *http.Request) (token Token, err error) ...@@ -87,6 +87,8 @@ func (a *AsapoAuthorizer) doRequest(req *http.Request) (token Token, err error)
//do nothing //do nothing
case http.StatusUnauthorized: case http.StatusUnauthorized:
return token, &AuthorizationError{errors.New("authorizer rejected to authorize: " + string(body)), http.StatusUnauthorized} return token, &AuthorizationError{errors.New("authorizer rejected to authorize: " + string(body)), http.StatusUnauthorized}
case http.StatusServiceUnavailable:
return token, &AuthorizationError{errors.New("authorizer service unavailable: " + string(body)), http.StatusServiceUnavailable}
default: default:
return token, errors.New("authorizer returned " + resp.Status + ": " + string(body)) return token, errors.New("authorizer returned " + resp.Status + ": " + string(body))
} }
......
...@@ -176,7 +176,7 @@ func (suite *ProcessRequestTestSuite) TestProcessRequestWithConnectionError() { ...@@ -176,7 +176,7 @@ func (suite *ProcessRequestTestSuite) TestProcessRequestWithConnectionError() {
w := doRequest("/beamtime/" + expectedBeamtimeId + "/" + expectedSource + "/" + expectedStream + "/" + expectedGroupID + "/next" + correctTokenSuffix) w := doRequest("/beamtime/" + expectedBeamtimeId + "/" + expectedSource + "/" + expectedStream + "/" + expectedGroupID + "/next" + correctTokenSuffix)
time.Sleep(time.Second) time.Sleep(time.Second)
suite.Equal(http.StatusNotFound, w.Code, "data not found") suite.Equal(http.StatusServiceUnavailable, w.Code, "data not found")
} }
func (suite *ProcessRequestTestSuite) TestProcessRequestWithInternalDBError() { func (suite *ProcessRequestTestSuite) TestProcessRequestWithInternalDBError() {
...@@ -191,7 +191,7 @@ func (suite *ProcessRequestTestSuite) TestProcessRequestWithInternalDBError() { ...@@ -191,7 +191,7 @@ func (suite *ProcessRequestTestSuite) TestProcessRequestWithInternalDBError() {
w := doRequest("/beamtime/" + expectedBeamtimeId + "/" + expectedSource + "/" + expectedStream + "/" + expectedGroupID + "/next" + correctTokenSuffix) w := doRequest("/beamtime/" + expectedBeamtimeId + "/" + expectedSource + "/" + expectedStream + "/" + expectedGroupID + "/next" + correctTokenSuffix)
time.Sleep(time.Second) time.Sleep(time.Second)
suite.Equal(http.StatusNotFound, w.Code, "internal error") suite.Equal(http.StatusServiceUnavailable, w.Code, "internal error")
} }
func (suite *ProcessRequestTestSuite) TestProcessRequestAddsCounter() { func (suite *ProcessRequestTestSuite) TestProcessRequestAddsCounter() {
......
...@@ -16,7 +16,7 @@ func writeAuthAnswer(w http.ResponseWriter, requestName string, db_name string, ...@@ -16,7 +16,7 @@ func writeAuthAnswer(w http.ResponseWriter, requestName string, db_name string,
case AuthorizationError: case AuthorizationError:
w.WriteHeader(er.statusCode) w.WriteHeader(er.statusCode)
default: default:
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusServiceUnavailable)
} }
w.Write([]byte(err.Error())) w.Write([]byte(err.Error()))
} }
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"asapo_common/utils" "asapo_common/utils"
"errors" "errors"
"net/http" "net/http"
"strconv"
_ "net/http/pprof" _ "net/http/pprof"
"strconv"
) )
func StartStatistics() { func StartStatistics() {
......
...@@ -9,7 +9,7 @@ const ( ...@@ -9,7 +9,7 @@ const (
const ( const (
//error codes //error codes
StatusTransactionInterrupted = http.StatusInternalServerError StatusTransactionInterrupted = http.StatusInternalServerError
StatusServiceUnavailable = http.StatusNotFound StatusServiceUnavailable = http.StatusServiceUnavailable
StatusWrongInput = http.StatusBadRequest StatusWrongInput = http.StatusBadRequest
StatusNoData = http.StatusConflict StatusNoData = http.StatusConflict
StatusPartialData = http.StatusPartialContent StatusPartialData = http.StatusPartialContent
......
...@@ -41,8 +41,6 @@ auto const kPartialData = ConsumerErrorTemplate { ...@@ -41,8 +41,6 @@ auto const kPartialData = ConsumerErrorTemplate {
"partial data", ConsumerErrorType::kPartialData "partial data", ConsumerErrorType::kPartialData
}; };
auto const kLocalIOError = ConsumerErrorTemplate { auto const kLocalIOError = ConsumerErrorTemplate {
"local i/o error", ConsumerErrorType::kLocalIOError "local i/o error", ConsumerErrorType::kLocalIOError
}; };
...@@ -76,8 +74,6 @@ auto const kUnavailableService = ConsumerErrorTemplate { ...@@ -76,8 +74,6 @@ auto const kUnavailableService = ConsumerErrorTemplate {
"service unavailable", ConsumerErrorType::kUnavailableService "service unavailable", ConsumerErrorType::kUnavailableService
}; };
} }
} }
......
...@@ -91,6 +91,8 @@ Error ConsumerErrorFromHttpCode(const RequestOutput* response, const HttpCode& c ...@@ -91,6 +91,8 @@ Error ConsumerErrorFromHttpCode(const RequestOutput* response, const HttpCode& c
return ConsumerErrorTemplates::kWrongInput.Generate(response->to_string()); return ConsumerErrorTemplates::kWrongInput.Generate(response->to_string());
case HttpCode::InternalServerError: case HttpCode::InternalServerError:
return ConsumerErrorTemplates::kInterruptedTransaction.Generate(response->to_string()); return ConsumerErrorTemplates::kInterruptedTransaction.Generate(response->to_string());
case HttpCode::ServiceUnavailable:
return ConsumerErrorTemplates::kUnavailableService.Generate(response->to_string());
case HttpCode::NotFound: case HttpCode::NotFound:
return ConsumerErrorTemplates::kUnavailableService.Generate(response->to_string()); return ConsumerErrorTemplates::kUnavailableService.Generate(response->to_string());
case HttpCode::Conflict: case HttpCode::Conflict:
......
...@@ -146,7 +146,7 @@ class ConsumerImplTests : public Test { ...@@ -146,7 +146,7 @@ class ConsumerImplTests : public Test {
void MockGetError() { void MockGetError() {
EXPECT_CALL(mock_http_client, Get_t(HasSubstr(expected_broker_api), _, _)).WillOnce(DoAll( EXPECT_CALL(mock_http_client, Get_t(HasSubstr(expected_broker_api), _, _)).WillOnce(DoAll(
SetArgPointee<1>(HttpCode::NotFound), SetArgPointee<1>(HttpCode::ServiceUnavailable),
SetArgPointee<2>(asapo::IOErrorTemplates::kUnknownIOError.Generate().release()), SetArgPointee<2>(asapo::IOErrorTemplates::kUnknownIOError.Generate().release()),
Return("") Return("")
)); ));
...@@ -442,7 +442,7 @@ TEST_F(ConsumerImplTests, GetMessageReturnsNoDataAfterTimeoutEvenIfOtherErrorOcc ...@@ -442,7 +442,7 @@ TEST_F(ConsumerImplTests, GetMessageReturnsNoDataAfterTimeoutEvenIfOtherErrorOcc
"/stream/0/" "/stream/0/"
+ std::to_string(expected_dataset_id) + "?token=" + std::to_string(expected_dataset_id) + "?token="
+ expected_token, _, _)).Times(AtLeast(1)).WillRepeatedly(DoAll( + expected_token, _, _)).Times(AtLeast(1)).WillRepeatedly(DoAll(
SetArgPointee<1>(HttpCode::NotFound), SetArgPointee<1>(HttpCode::ServiceUnavailable),
SetArgPointee<2>(nullptr), SetArgPointee<2>(nullptr),
Return(""))); Return("")));
...@@ -1400,7 +1400,7 @@ TEST_F(ConsumerImplTests, NegativeAcknowledgeUsesCorrectUri) { ...@@ -1400,7 +1400,7 @@ TEST_F(ConsumerImplTests, NegativeAcknowledgeUsesCorrectUri) {
TEST_F(ConsumerImplTests, CanInterruptOperation) { TEST_F(ConsumerImplTests, CanInterruptOperation) {
EXPECT_CALL(mock_http_client, Get_t(_, _, _)).Times(AtLeast(1)).WillRepeatedly(DoAll( EXPECT_CALL(mock_http_client, Get_t(_, _, _)).Times(AtLeast(1)).WillRepeatedly(DoAll(
SetArgPointee<1>(HttpCode::NotFound), SetArgPointee<1>(HttpCode::ServiceUnavailable),
SetArgPointee<2>(nullptr), SetArgPointee<2>(nullptr),
Return(""))); Return("")));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment