Split the service header into internal and external parts

The service header in include/maxscale/ contains the public part of the
service API. These functions can be safely used by the modules.

The internal header located in service/core/maxscale/ is used by the core
to initialize MaxScale at startup or to provide other services in a more
controlled way (the config_runtime, for example).
This commit is contained in:
Markus Makela
2016-11-25 15:10:19 +02:00
parent 88677946f8
commit 691989ff04
8 changed files with 137 additions and 101 deletions

View File

@ -187,60 +187,6 @@ typedef enum count_spec_t
#define SERVICE_STATE_FAILED 3 /**< The service failed to start */ #define SERVICE_STATE_FAILED 3 /**< The service failed to start */
#define SERVICE_STATE_STOPPED 4 /**< The service has been stopped */ #define SERVICE_STATE_STOPPED 4 /**< The service has been stopped */
/**
* Service life cycle management
*
* These functions should only be called by the MaxScale core.
*/
/**
* @brief Allocate a new service
*
* @param name The service name
* @param router The router module this service uses
*
* @return The newly created service or NULL if an error occurred
*/
SERVICE* service_alloc(const char *name, const char *router);
/**
* @brief Free the specified service
*
* @param service The service to free
*/
void service_free(SERVICE *service);
/**
* @brief Shut all services down
*
* Stops all services and calls the destroyInstance entry points for all routers
* and filter. This should only be called once by the main shutdown code.
*/
void service_shutdown(void);
/**
* @brief Launch all services
*
* Initialize and start all services. This should only be called once by the
* main initialization code.
*
* @return Number of successfully started services
*/
int service_launch_all(void);
/**
* Creating and adding new components to services
*/
SERV_LISTENER* serviceCreateListener(SERVICE *service, const char *name,
const char *protocol, const char *address,
unsigned short port, const char *authenticator,
const char *options, SSL_LISTENER *ssl);
int serviceHasProtocol(SERVICE *service, const char *protocol,
const char* address, unsigned short port);
void serviceAddBackend(SERVICE *service, SERVER *server);
void serviceRemoveBackend(SERVICE *service, const SERVER *server);
bool serviceHasBackend(SERVICE *service, SERVER *server);
/** /**
* Starting and stopping services * Starting and stopping services
*/ */
@ -282,23 +228,14 @@ bool serviceStopListener(SERVICE *service, const char *name);
/** /**
* Utility functions * Utility functions
*/ */
char* service_get_name(SERVICE* service);
bool service_all_services_have_listeners(void);
SERVICE* service_find(const char *name); SERVICE* service_find(const char *name);
int service_isvalid(SERVICE *service);
/** // TODO: Change binlogrouter to use the functions in config_runtime.h
* Alteration of the service configuration void serviceAddBackend(SERVICE *service, SERVER *server);
*/
void serviceAddRouterOption(SERVICE *service, char *option);
void serviceClearRouterOptions(SERVICE *service);
int serviceSetUser(SERVICE *service, char *user, char *auth);
int serviceGetUser(SERVICE *service, char **user, char **auth); int serviceGetUser(SERVICE *service, char **user, char **auth);
int serviceSetUser(SERVICE *service, char *user, char *auth);
bool serviceSetFilters(SERVICE *service, char *filters); bool serviceSetFilters(SERVICE *service, char *filters);
int serviceSetSSL(SERVICE *service, char* action);
int serviceSetSSLVersion(SERVICE *service, char* version);
int serviceSetSSLVerifyDepth(SERVICE* service, int depth);
void serviceSetCertificates(SERVICE *service, char* cert, char* key, char* ca_cert);
int serviceEnableRootUser(SERVICE *service, int action); int serviceEnableRootUser(SERVICE *service, int action);
int serviceSetTimeout(SERVICE *service, int val); int serviceSetTimeout(SERVICE *service, int val);
int serviceSetConnectionLimits(SERVICE *service, int max, int queued, int timeout); int serviceSetConnectionLimits(SERVICE *service, int max, int queued, int timeout);
@ -308,16 +245,11 @@ char* serviceGetWeightingParameter(SERVICE *service);
int serviceEnableLocalhostMatchWildcardHost(SERVICE *service, int action); int serviceEnableLocalhostMatchWildcardHost(SERVICE *service, int action);
int serviceStripDbEsc(SERVICE* service, int action); int serviceStripDbEsc(SERVICE* service, int action);
int serviceAuthAllServers(SERVICE *service, int action); int serviceAuthAllServers(SERVICE *service, int action);
void service_update(SERVICE *service, char *router, char *user, char *auth);
int service_refresh_users(SERVICE *service); int service_refresh_users(SERVICE *service);
bool service_set_param_value(SERVICE* service, CONFIG_PARAMETER* param, char* valstr,
count_spec_t count_spec, config_param_type_t type);
/** /**
* Diagnostics * Diagnostics
*/ */
void printService(SERVICE *service);
void printAllServices(void);
void dprintAllServices(DCB *dcb); void dprintAllServices(DCB *dcb);
void dprintService(DCB *dcb, SERVICE *service); void dprintService(DCB *dcb, SERVICE *service);
void dListServices(DCB *dcb); void dListServices(DCB *dcb);
@ -339,27 +271,4 @@ static inline uint64_t service_get_capabilities(const SERVICE *service)
return service->capabilities; return service->capabilities;
} }
/**
* Check if a service uses @c servers
* @param server Server that is queried
* @return True if server is used by at least one service
*/
bool service_server_in_use(const SERVER *server);
/**
* @brief Serialize a service to a file
*
* This partially converts @c service into an INI format file. Only the servers
* of the service are serialized. This allows the service to keep using the servers
* added at runtime even after a restart.
*
* NOTE: This does not persist the complete service configuration and requires
* that an existing service configuration is in the main configuration file.
* Changes to service parameters are not persisted.
*
* @param service Service to serialize
* @return False if the serialization of the service fails, true if it was successful
*/
bool service_serialize_servers(const SERVICE *service);
MXS_END_DECLS MXS_END_DECLS

View File

@ -62,11 +62,12 @@
#include <maxscale/monitor.h> #include <maxscale/monitor.h>
#include <maxscale/notification.h> #include <maxscale/notification.h>
#include <maxscale/pcre2.h> #include <maxscale/pcre2.h>
#include <maxscale/service.h>
#include <maxscale/spinlock.h> #include <maxscale/spinlock.h>
#include <maxscale/utils.h> #include <maxscale/utils.h>
#include <maxscale/gwdirs.h> #include <maxscale/gwdirs.h>
#include "maxscale/service.h"
typedef struct duplicate_context typedef struct duplicate_context
{ {
HASHTABLE *hash; HASHTABLE *hash;

View File

@ -17,6 +17,8 @@
#include <maxscale/gwdirs.h> #include <maxscale/gwdirs.h>
#include <maxscale/spinlock.h> #include <maxscale/spinlock.h>
#include "maxscale/service.h"
static SPINLOCK crt_lock = SPINLOCK_INIT; static SPINLOCK crt_lock = SPINLOCK_INIT;
bool runtime_link_server(SERVER *server, const char *target) bool runtime_link_server(SERVER *server, const char *target)

View File

@ -66,14 +66,14 @@
#include <maxscale/poll.h> #include <maxscale/poll.h>
#include <maxscale/query_classifier.h> #include <maxscale/query_classifier.h>
#include <maxscale/server.h> #include <maxscale/server.h>
#include <maxscale/service.h>
#include <maxscale/service.h>
#include <maxscale/session.h> #include <maxscale/session.h>
#include <maxscale/statistics.h> #include <maxscale/statistics.h>
#include <maxscale/thread.h> #include <maxscale/thread.h>
#include <maxscale/utils.h> #include <maxscale/utils.h>
#include <maxscale/version.h> #include <maxscale/version.h>
#include "maxscale/service.h"
#define STRING_BUFFER_SIZE 1024 #define STRING_BUFFER_SIZE 1024
#define PIDFD_CLOSED -1 #define PIDFD_CLOSED -1

View File

@ -0,0 +1,121 @@
#pragma once
/*
* Copyright (c) 2016 MariaDB Corporation Ab
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl.
*
* Change Date: 2019-07-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
#include <maxscale/service.h>
MXS_BEGIN_DECLS
/**
* @file service.h - MaxScale internal service functions
*/
/**
* Service life cycle management
*
* These functions should only be called by the MaxScale core.
*/
/**
* @brief Allocate a new service
*
* @param name The service name
* @param router The router module this service uses
*
* @return The newly created service or NULL if an error occurred
*/
SERVICE* service_alloc(const char *name, const char *router);
/**
* @brief Free the specified service
*
* @param service The service to free
*/
void service_free(SERVICE *service);
/**
* @brief Shut all services down
*
* Stops all services and calls the destroyInstance entry points for all routers
* and filter. This should only be called once by the main shutdown code.
*/
void service_shutdown(void);
/**
* @brief Launch all services
*
* Initialize and start all services. This should only be called once by the
* main initialization code.
*
* @return Number of successfully started services
*/
int service_launch_all(void);
/**
* Creating and adding new components to services
*/
SERV_LISTENER* serviceCreateListener(SERVICE *service, const char *name,
const char *protocol, const char *address,
unsigned short port, const char *authenticator,
const char *options, SSL_LISTENER *ssl);
int serviceHasProtocol(SERVICE *service, const char *protocol,
const char* address, unsigned short port);
void serviceRemoveBackend(SERVICE *service, const SERVER *server);
bool serviceHasBackend(SERVICE *service, SERVER *server);
/**
* @brief Serialize a service to a file
*
* This partially converts @c service into an INI format file. Only the servers
* of the service are serialized. This allows the service to keep using the servers
* added at runtime even after a restart.
*
* NOTE: This does not persist the complete service configuration and requires
* that an existing service configuration is in the main configuration file.
* Changes to service parameters are not persisted.
*
* @param service Service to serialize
* @return False if the serialization of the service fails, true if it was successful
*/
bool service_serialize_servers(const SERVICE *service);
/**
* Internal utility functions
*/
char* service_get_name(SERVICE* service);
bool service_all_services_have_listeners(void);
int service_isvalid(SERVICE *service);
/**
* Check if a service uses @c servers
* @param server Server that is queried
* @return True if server is used by at least one service
*/
bool service_server_in_use(const SERVER *server);
/**
* Alteration of the service configuration
*/
void serviceAddRouterOption(SERVICE *service, char *option);
void serviceClearRouterOptions(SERVICE *service);
void service_update(SERVICE *service, char *router, char *user, char *auth);
bool service_set_param_value(SERVICE* service, CONFIG_PARAMETER* param, char* valstr,
count_spec_t count_spec, config_param_type_t type);
/**
* Internal debugging diagnostics
*/
void printService(SERVICE *service);
void printAllServices(void);
MXS_END_DECLS

View File

@ -48,7 +48,6 @@
#include <math.h> #include <math.h>
#include <fcntl.h> #include <fcntl.h>
#include <maxscale/session.h> #include <maxscale/session.h>
#include <maxscale/service.h>
#include <maxscale/gw_protocol.h> #include <maxscale/gw_protocol.h>
#include <maxscale/listener.h> #include <maxscale/listener.h>
#include <maxscale/server.h> #include <maxscale/server.h>
@ -68,6 +67,8 @@
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include <maxscale/utils.h> #include <maxscale/utils.h>
#include "maxscale/service.h"
/** Base value for server weights */ /** Base value for server weights */
#define SERVICE_BASE_SERVER_WEIGHT 1000 #define SERVICE_BASE_SERVER_WEIGHT 1000

View File

@ -33,7 +33,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <maxscale/maxscale_test.h> #include <maxscale/maxscale_test.h>
#include <maxscale/service.h> #include "../maxscale/service.h"
#include <maxscale/gwdirs.h> #include <maxscale/gwdirs.h>
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include "test_utils.h" #include "test_utils.h"

View File

@ -26,7 +26,6 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <time.h> #include <time.h>
#include <maxscale/service.h>
#include <maxscale/server.h> #include <maxscale/server.h>
#include <maxscale/router.h> #include <maxscale/router.h>
#include <maxscale/atomic.h> #include <maxscale/atomic.h>
@ -47,6 +46,9 @@
#include <maxscale/version.h> #include <maxscale/version.h>
// This isn't really a clean way of testing
#include "../../../../core/maxscale/service.h"
static void printVersion(const char *progname); static void printVersion(const char *progname);
static void printUsage(const char *progname); static void printUsage(const char *progname);
extern int blr_test_parse_change_master_command(char *input, char *error_string, CHANGE_MASTER_OPTIONS *config); extern int blr_test_parse_change_master_command(char *input, char *error_string, CHANGE_MASTER_OPTIONS *config);