bool Service::finishLoad() { setStatus(SS_WORKING); if (!isShell()) { if (true) { LoadServiceNotice notice; notice.shellServiceInfos.push_back(ServiceInfo( getServiceDockerID(), getServiceType(), getServiceID(), getServiceName(), getStatus(), getClientDockerID(), getClientSessionID())); Docker::getRef().broadcastToDockers(notice, false); } if (getServiceTrait(getServiceType()) == STrait_Multi) { RefreshServiceToMgrNotice refreshNotice; refreshNotice.shellServiceInfos.push_back(ServiceInfo( getServiceDockerID(), getServiceType(), getServiceID(), getServiceName(), getStatus(), getClientDockerID(), getClientSessionID())); for (auto sd : ServiceDepends) { if (getServiceTrait(sd.first) == STrait_Single ) { toService(sd.first, refreshNotice, nullptr); } } } LOGI(*this << "local service finish load. service=" << getServiceName() << ", id=" << getServiceID()); } else { LOGI(*this << "remote service finish load. service=" << getServiceName() << ", id=" << getServiceID()); } return true; }
// initialize remote log from the properties file. // ideally this is done in Log::initialize however due to // the dependency of remote log on connection which depends on log // (see base_init in am_main.cpp) this is done seperately. am_status_t Log::initializeRemoteLog(const Properties& propertiesRef) throw() { am_status_t status = AM_SUCCESS; // Create logging servcie URL from naming service since no // sso token is available to read the naming service. try { const std::string namingservice("/namingservice"); const std::string loggingservice("/loggingservice"); const std::string namingURL( propertiesRef.get(AM_COMMON_NAMING_URL_PROPERTY, "")); std::string logURL = namingURL; std::size_t pos = 0; pos = logURL.find (namingservice, pos); while (pos != std::string::npos) { logURL.replace(pos, namingservice.size(), loggingservice); pos = logURL.find (namingservice, pos + 1); } URL verifyURL(logURL); LogService *newLogSvc = new LogService(ServiceInfo(logURL), propertiesRef, propertiesRef.get( AM_COMMON_CERT_DB_PASSWORD_PROPERTY,""), propertiesRef.get( AM_AUTH_CERT_ALIAS_PROPERTY, ""), propertiesRef.getBool( AM_COMMON_TRUST_SERVER_CERTS_PROPERTY, false), 1); Log::setRemoteInfo(newLogSvc); } catch (std::bad_alloc& exb) { status = AM_NO_MEMORY; } catch (std::exception& exs) { status = AM_INVALID_ARGUMENT; } catch (...) { status = AM_FAILURE; } return status; }
/* * Validate App SSOToken */ am_status_t AgentProfileService::validateAgentSSOToken() { am_status_t sts = AM_FAILURE; const char *thisfunc = "AgentProfileService::validateAgentSSOToken()"; SessionInfo *sessionInfo = NULL; try { sessionInfo = new SessionInfo(); Http::CookieList cookieList; SSOTokenService *ssoTokenSvc = get_sso_token_service(); sts = ssoTokenSvc->getSessionInfo(ServiceInfo(), agentSSOToken, cookieList, false, *sessionInfo, true); if (sts == AM_SUCCESS) { sts = sessionInfo->isValid() ? AM_SUCCESS : AM_INVALID_SESSION; } else { Log::log(logModule, Log::LOG_ERROR, "%s: Invalid Agent(app) SSO token %s.", thisfunc, agentSSOToken.c_str()); } } catch (InternalException& ex) { Log::log(logModule, Log::LOG_ERROR, ex); sts = AM_FAILURE; } catch (std::bad_alloc& exb) { Log::log(logModule, Log::LOG_ERROR, exb); sts = AM_NO_MEMORY; } catch (std::exception& exs) { Log::log(logModule, Log::LOG_ERROR, exs); sts = AM_FAILURE; } catch (...) { Log::log(logModule, Log::LOG_ERROR, "%s: Unknown exception encountered."); sts = AM_FAILURE; } if(sessionInfo != NULL) { delete sessionInfo; } return sts; }
bool Service::finishUnload() { setStatus(SS_DESTROY); if (!isShell()) { if (getServiceTrait(getServiceType()) == STrait_Multi) { RefreshServiceToMgrNotice refreshNotice; refreshNotice.shellServiceInfos.push_back(ServiceInfo( getServiceDockerID(), getServiceType(), getServiceID(), getServiceName(), getStatus(), getClientDockerID(), getClientSessionID())); for (auto sd : ServiceDepends) { if (getServiceTrait(sd.first) == STrait_Single) { toService(sd.first, refreshNotice, nullptr); } } } UnloadedServiceNotice notice(getServiceType(), getServiceID()); Docker::getRef().broadcastToDockers(notice, true); LOGI(*this << "local service finish unload. service=" << getServiceName() << ", id=" << getServiceID()); } else { LOGI(*this << "remote service finish unload. service=" << getServiceName() << ", id=" << getServiceID()); } for (auto tID : _repeatTimers) { SessionManager::getRef().cancelTimer(tID); } _repeatTimers.clear(); return true; }
extern "C" am_status_t am_log_set_remote_info(const char *rem_log_url, const char *sso_token_id, const char *rem_log_name, const am_properties_t properties) { am_status_t retVal = AM_SUCCESS; if (rem_log_url == NULL || sso_token_id == NULL || rem_log_name == NULL || properties == NULL) { retVal = AM_INVALID_ARGUMENT; } else if (!Log::isInitialized()) { retVal = AM_SERVICE_NOT_INITIALIZED; } else { try { SSOToken ssoToken = SSOToken(sso_token_id); const Properties *prop = reinterpret_cast<const Properties *>(properties); LogService *newLogSvc = new LogService(ServiceInfo(rem_log_url), ssoToken, Http::CookieList(), rem_log_name, *prop, (*prop).get(AM_COMMON_CERT_DB_PASSWORD_PROPERTY,""), (*prop).get(AM_AUTH_CERT_ALIAS_PROPERTY,""), (*prop).getBool(AM_COMMON_TRUST_SERVER_CERTS_PROPERTY, false)); Log::setRemoteInfo(newLogSvc); } catch (InternalException& ex) { retVal = ex.getStatusCode(); } catch (...) { retVal = AM_FAILURE; } } return retVal; }