# Sample binary
src/libedge-orchestration/lib/*
src/libedge-orchestration/sample/orchestration_sample
+src/libedge-orchestration/sample/orchestration_chrome_sample
# Test binary, build with `go test -c`
*.test
# Output of c build
*.o
+src/CMain/unittest/out/*
src/CMain/bin/*
+# Output of go build
+src/GoMain/bin/*
+
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
*.html
LIBSCORE_SAMPLE_CONF := myscoring.conf
LIBSCORE_SAMPLE_DIR := $(BASE_DIR)/src/scoringmgr/mock/myscoring
+LIBSCORE_SAMPLE_2 := myscoring2
+LIBSCORE_SAMPLE_2_LIBRARY := libmyscoring2.so
+LIBSCORE_SAMPLE_2_VER := 1.0.1
+LIBSCORE_SAMPLE_2_CONF := myscoring2.conf
+LIBSCORE_SAMPLE_2_DIR := $(BASE_DIR)/src/scoringmgr/mock/myscoring2
+
.DEFAULT_GOAL := help
ls -al $(LIBPKG_LIB_DIR)
ls -al $(LIBPKG_INC_DIR)
$(MAKE) -C $(LIBSCORE_SAMPLE_DIR)
+ $(MAKE) -C $(LIBSCORE_SAMPLE_2_DIR)
## install output files for packaing
install:
install -d $(DESTDIR)/etc/dbus-1/system.d
install -m 755 $(CMAIN_BIN_DIR)/$(CMAIN_BIN_FILE) $(DESTDIR)/usr/bin/$(CMAIN_BIN_FILE)
install -m 755 $(LIBPKG_SAMPLE_DIR)/orchestration_sample $(DESTDIR)/usr/bin/orchestration_sample
+ install -m 755 $(LIBPKG_SAMPLE_DIR)/orchestration_chrome_sample $(DESTDIR)/usr/bin/orchestration_chrome_sample
install -m 644 $(BASE_DIR)/$(SERVICE_FILE) $(DESTDIR)/usr/lib/systemd/system/$(SERVICE_FILE)
ln -s ../$(SERVICE_FILE) $(DESTDIR)/usr/lib/systemd/system/multi-user.target.wants/
install -m 644 $(LIBPKG_INC_DIR)/$(LIBPKG_HEADER_FILE) $(DESTDIR)/usr/include/$(PKG_NAME)
install -d $(DESTDIR)/etc/$(PKG_NAME)/$(LIBSCORE_SAMPLE)
+ install -d $(DESTDIR)/etc/$(PKG_NAME)/$(LIBSCORE_SAMPLE_2)
install -m 644 $(LIBSCORE_SAMPLE_DIR)/$(LIBSCORE_SAMPLE_CONF) $(DESTDIR)/etc/$(PKG_NAME)/$(LIBSCORE_SAMPLE)/
-# install -m 644 $(LIBSCORE_SAMPLE_DIR)/$(LIBSCORE_SAMPLE_LIBRARY) $(DESTDIR)/etc/$(PKG_NAME)/$(LIBSCORE_SAMPLE)/
+ install -m 644 $(LIBSCORE_SAMPLE_2_DIR)/$(LIBSCORE_SAMPLE_2_CONF) $(DESTDIR)/etc/$(PKG_NAME)/$(LIBSCORE_SAMPLE_2)/
install -m 644 $(LIBSCORE_SAMPLE_DIR)/$(LIBSCORE_SAMPLE_LIBRARY).$(LIBSCORE_SAMPLE_VER) $(DESTDIR)/etc/$(PKG_NAME)/$(LIBSCORE_SAMPLE)/
+ install -m 644 $(LIBSCORE_SAMPLE_2_DIR)/$(LIBSCORE_SAMPLE_2_LIBRARY).$(LIBSCORE_SAMPLE_2_VER) $(DESTDIR)/etc/$(PKG_NAME)/$(LIBSCORE_SAMPLE_2)/
## go test and coverage
test:
%post -n libedge-orchestration
ln -sf %{_sysconfdir}/%{name}/myscoring/libmyscoring.so.1.0.1 %{_sysconfdir}/%{name}/myscoring/libmyscoring.so
+ln -sf %{_sysconfdir}/%{name}/myscoring2/libmyscoring2.so.1.0.1 %{_sysconfdir}/%{name}/myscoring2/libmyscoring2.so
%files
%manifest %{name}.manifest
%attr(755,system_fw,system_fw)%{_libdir}/liborchestration-client.so
# orchestration sample
%attr(755,system_fw,system_fw)%{_bindir}/orchestration_sample
+%attr(755,system_fw,system_fw)%{_bindir}/orchestration_chrome_sample
%attr(755,system_fw,system_fw)%{_sysconfdir}/%{name}/myscoring/*
+%attr(755,system_fw,system_fw)%{_sysconfdir}/%{name}/myscoring2/*
%files -n libedge-orchestration-devel
%manifest lib%{name}.manifest
-../../../interface/output/inc/linux_aarch64/liborchestration-0.0.1-20190429.1714.h
\ No newline at end of file
+../../../interface/output/inc/linux_aarch64/liborchestration-0.0.1-20190514.1301.h
\ No newline at end of file
-../../../interface/output/inc/linux_arm/liborchestration-0.0.1-20190429.1714.h
\ No newline at end of file
+../../../interface/output/inc/linux_arm/liborchestration-0.0.1-20190514.1301.h
\ No newline at end of file
-../../../interface/output/inc/linux_x86-64/liborchestration-0.0.1-20190429.1706.h
\ No newline at end of file
+../../../interface/output/inc/linux_x86-64/liborchestration-0.0.1-20190514.1259.h
\ No newline at end of file
-../../../interface/output/inc/linux_x86/liborchestration-0.0.1-20190429.1714.h
\ No newline at end of file
+../../../interface/output/inc/linux_x86/liborchestration-0.0.1-20190514.1301.h
\ No newline at end of file
-../../../interface/output/lib/linux_aarch64/liborchestration-0.0.1-20190429.1714.a
\ No newline at end of file
+../../../interface/output/lib/linux_aarch64/liborchestration-0.0.1-20190514.1301.a
\ No newline at end of file
-../../../interface/output/lib/linux_arm/liborchestration-0.0.1-20190429.1714.a
\ No newline at end of file
+../../../interface/output/lib/linux_arm/liborchestration-0.0.1-20190514.1301.a
\ No newline at end of file
-../../../interface/output/lib/linux_x86-64/liborchestration-0.0.1-20190429.1706.a
\ No newline at end of file
+../../../interface/output/lib/linux_x86-64/liborchestration-0.0.1-20190514.1259.a
\ No newline at end of file
-../../../interface/output/lib/linux_x86/liborchestration-0.0.1-20190429.1714.a
\ No newline at end of file
+../../../interface/output/lib/linux_x86/liborchestration-0.0.1-20190514.1301.a
\ No newline at end of file
build-sample: build
$(CC) -Wall -fPIE -pie $(SAMPLE_DIR)/main.c -o $(SAMPLE_DIR)/orchestration_sample -I$(INC_DIR) -L$(LIB_DIR) -lorchestration-client `pkg-config --libs --cflags gio-2.0 gio-unix-2.0 glib-2.0`
+ $(CC) -Wall -fPIE -pie $(SAMPLE_DIR)/main_chrome.c -o $(SAMPLE_DIR)/orchestration_chrome_sample -I$(INC_DIR) -L$(LIB_DIR) -lorchestration-client `pkg-config --libs --cflags gio-2.0 gio-unix-2.0 glib-2.0`
-rm -f ./sample/*.o
build:
int main() {
orchestration_service_info_s service_info;
- service_info.exec_parameter = "-al";
- orchestration_request_service("ls", service_info, status_cb, NULL);
+ service_info.exec_parameter = "ls -al";
+ orchestration_request_service("list_segments", service_info, status_cb, NULL);
return 0;
}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright 2019 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *******************************************************************************/
+
+#include <stdio.h>
+#include <orchestration_client.h>
+
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <netinet/in.h>
+#include <net/if.h>
+#include <arpa/inet.h>
+
+int get_ip_addr(char ipstr[40]) {
+ int fd;
+ struct ifreq ifr;
+
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+ ifr.ifr_addr.sa_family = AF_INET;
+
+ /* I want IP address attached to "wlan0" */
+ strncpy(ifr.ifr_name, "wlan0", IFNAMSIZ-1);
+ ioctl(fd, SIOCGIFADDR, &ifr);
+ close(fd);
+
+ strcpy(ipstr, inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));
+ return 0;
+}
+
+void status_cb(orchestration_service_status_e staus, void* user_data)
+{
+
+}
+
+int main() {
+ char command[256] = "/usr/share/chromium-efl/bin/efl_webprocess --type=renderer --enable-castanets=";
+ char ipstr[40] = {0, };
+ if (get_ip_addr(ipstr) != 0) {
+ printf("error from getting ip addr\n");
+ return 0;
+ }
+ orchestration_service_info_s service_info;
+ service_info.exec_parameter = strcat(command, ipstr);
+ printf("service_info.exec_parameter: %s\n", service_info.exec_parameter);
+ orchestration_request_service("org.tizen.chromium-efl", service_info, status_cb, NULL);
+ return 0;
+}
\ No newline at end of file
targetCustomURL = fmt.Sprintf("127.0.0.1:%d", httpclient.ConstWellknownPort)
targetRemoteDeviceAddr = "127.0.0.1"
- notExistFileName = "NotExistFile"
keyFilePath = "../../securemgr/test/key.txt"
serviceName = "ls"
+
+ userArgs = []string{"ls", "-ail"}
+ userArgsNotExist = []string{"NotExistFile"}
)
func init() {
appInfo := make(map[string]interface{})
appInfo["ServiceName"] = serviceName
+ appInfo["UserArgs"] = userArgs
appInfo["NotificationTargetURL"] = targetRemoteDeviceAddr
err := httpclient.DoExecuteRemoteDevice(appInfo, targetRemoteDeviceAddr)
setUp()
appInfo := make(map[string]interface{})
- appInfo["ServiceName"] = notExistFileName
+ appInfo["ServiceName"] = serviceName
+ appInfo["UserArgs"] = userArgsNotExist
err := httpclient.DoExecuteRemoteDevice(appInfo, targetRemoteDeviceAddr)
log.Println("[err]", err)
return
}
- _, err = exec.LookPath(distService["ServiceName"].(string))
+ _, err = exec.LookPath((distService["UserArgs"].([]interface{}))[0].(string))
if err != nil {
err = errors.New("It is Invalid Service")
return
// Scoring mgr URI
ConstScoremgrScore = "/api/v1/scoringmgr/score"
- ConstAppName = "ls"
- ConstNotExistAppName = "NotExistFile"
- ConstTooLongAppName = `00000000000000000000000000000000000000000000000000000000000000000000000000000000000
+ ConstAppName = "ls"
+ ConstTooLongAppName = `00000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000`
)
+var (
+ userArgs = []string{"ls", "-ail"}
+ userArgsNotExist = []string{"invalidArgs"}
+)
+
type Response struct {
Content string
Code int
}
func TestAPIV1ServicemgrServicesPost(t *testing.T) {
- executeService(t, ConstAppName, http.StatusOK)
+ executeService(t, ConstAppName, userArgs, http.StatusOK)
}
func TestAPIV1ServicemgrServicesPostWithNotExistExecutionFile(t *testing.T) {
- executeService(t, ConstNotExistAppName, http.StatusBadRequest)
+ executeService(t, ConstAppName, userArgsNotExist, http.StatusBadRequest)
}
func TestAPIV1ScoringmgrScoreLibnameGet(t *testing.T) {
return
}
-func executeService(t *testing.T, appName string, expectedStatus int) {
+func executeService(t *testing.T, appName string, userArgs []string, expectedStatus int) {
t.Helper()
targetURI := ConstServicemgrServices
appInfo["ServiceID"] = 1
appInfo["ServiceName"] = appName
appInfo["NotificationTargetURL"] = "URL"
-
- userArgs := []string{"-ail"}
appInfo["UserArgs"] = userArgs
bdbytes, err := json.Marshal(appInfo)
ConfVersion=v0.0 ; Version of Configuration file
[ServiceInfo]
-ServiceName=ls ; Name of distributed service
+ServiceName=list_segments ; Name of distributed service
[ScoringMethod]
LibFile=./libmyscoring.so ; Library file name
--- /dev/null
+#
+# Makefile
+#
+
+# Target parameters
+LIBRARY_FILE := libmyscoring2.so
+LIBRARY_VER := 1.0.1
+SRC_FILES := \
+ myscoring.c
+CONF_FILE := myscoring2.conf
+OBJ_FILES := *.o
+
+# Build parameter
+
+all: clean build
+
+build:
+ $(CC) -fPIC -c $(SRC_FILES)
+ $(CC) -shared -o $(LIBRARY_FILE).$(LIBRARY_VER) $(OBJ_FILES) -lm
+ ln -sf $(LIBRARY_FILE).$(LIBRARY_VER) $(LIBRARY_FILE)
+ -rm -f $(OBJ_FILES)
+
+clean:
+ -rm -f $(OBJ_FILES)
+ -rm -f $(LIBRARY_FILE).$(LIBRARY_VER)
+ -rm -f $(LIBRARY_FILE)
+
+.PHONY: build clean
\ No newline at end of file
-libmyscoring.so.1.0.1
\ No newline at end of file
+libmyscoring2.so.1.0.1
\ No newline at end of file
/*
-$ gcc -fPIC -c myscoring.c && gcc -shared -o -lm libmyscoring.so.1.0.1 myscoring.o -lm
+$ gcc -fPIC -c myscoring.c && gcc -shared -o libmyscoring.so.1.0.1 myscoring.o -lm
$ ln -rs libmyscoring.so.1.0.1 libmyscoring.so
*/
return score;
}
+
+#define MY_SCORING_3_CNT 4
+double myscoring3(double (*getResource)(const char *))
+{
+
+ // printf("myscoring\n");
+
+ double score;
+ const char *resourceNames[MY_SCORING_3_CNT] = {"cpu/usage", "cpu/count", "memory/free", "memory/available"};
+ double W[MY_SCORING_3_CNT] = {1.48271, 4.125421, 5.3381723, 9.194717234};
+ double resourceValues[MY_SCORING_3_CNT];
+
+ // double someResource;
+ // someResource = getResource("some/usage");
+ // assert(isnan(someResource));
+
+ for (int i = 0; i < MY_SCORING_3_CNT; i++)
+ {
+ resourceValues[i] = getResource(resourceNames[i]);
+ // printf("resourceNames : %s %f\n", resourceNames[i], resourceValues[i]);
+ }
+
+ score = 0.0;
+ for (int i = 0; i < MY_SCORING_3_CNT; i++)
+ {
+ score += resourceValues[i] * W[i];
+ }
+
+ return score;
+}
ConfVersion=v0.0 ; Version of Configuration file
[ServiceInfo]
-ServiceName=ll ; Name of distributed service
+ServiceName=org.tizen.chromium-efl ; Name of distributed service
[ScoringMethod]
LibFile=./libmyscoring.so ; Library file name
-FunctionName=myscoring2
+FunctionName=myscoring3
[ResourceType]
IntervalTimeMs=1000 ; Interval time of get resource
package servicemgr
import (
+ "bufio"
+ "errors"
"log"
"os"
"os/exec"
cmd, pid, err := p.setService()
if err != nil {
+ log.Println(err)
return
}
log.Println(logPrefix, "Just ran subprocess ", pid)
}
func (p Service) setService() (cmd *exec.Cmd, pid int, err error) {
- if len(p.paramStr) == 0 {
- cmd = exec.Command(p.serviceName)
- } else {
- cmd = exec.Command(p.serviceName, p.paramStr...)
+ if len(p.paramStr) < 1 {
+ err = errors.New("error: empty parameter")
+ return
}
+ cmd = exec.Command(p.paramStr[0], p.paramStr[1:]...)
+
+ // set "owner" account: need to execute user app
+ /*
+ execUser, _ := user.Lookup("owner")
+
+ uid, _ := strconv.Atoi(execUser.Uid)
+ gid, _ := strconv.Atoi(execUser.Gid)
+ groups, _ := execUser.GroupIds()
+
+ var gids = []uint32{}
+ for _, i := range groups {
+ id, _ := strconv.Atoi(i)
+ gids = append(gids, uint32(id))
+ }
+
+ log.Printf("uid(%d), gid(%d)", uid, gid)
+ log.Printf("groupIds: %v", gids)
- cmd.Stdout = os.Stdout
+ cmd.SysProcAttr = &syscall.SysProcAttr{}
+ cmd.SysProcAttr.Credential = &syscall.Credential{
+ Uid: uint32(uid),
+ Gid: uint32(gid),
+ Groups: gids,
+ }
+ */
+ stdout, _ := cmd.StdoutPipe()
err = cmd.Start()
if err != nil {
log.Println(logPrefix, err.Error())
return
}
+ scanner := bufio.NewScanner(stdout)
+ for scanner.Scan() {
+ m := scanner.Text()
+ log.Println(m)
+ }
+
pid = cmd.Process.Pid
return
func executeLocalEnv(appInfo map[string]interface{}) (err error) {
// check execution validation
- _, err = exec.LookPath(appInfo[ConstKeyServiceName].(string))
+ _, err = exec.LookPath((appInfo[ConstKeyUserArgs].([]string))[0])
if checkError(err) == false {
go Run(appInfo)
)
var (
+ paramStr = []string{"ls"}
+ paramStrWithArgs = []string{"ls", "-ail"}
+ paramStrWithInvalidArgs = []string{"ls", "invalidArgs"}
+)
+
+var (
targetLocalAddr, _ = common.GetOutboundIP()
serviceID uint64
// notExistFileName = "NotExistFile"
func TestExecuteApp(t *testing.T) {
notiChan := make(chan string)
- _, err := servicemgr.ExecuteApp(targetLocalAddr, serviceName, nil, notiChan)
+ _, err := servicemgr.ExecuteApp(targetLocalAddr, serviceName, paramStr, notiChan)
checkError(t, err)
time.Sleep(time.Millisecond * 10)
func TestExecuteAppWithArgs(t *testing.T) {
notiChan := make(chan string)
- args := []string{"-ail"}
- _, err := servicemgr.ExecuteApp(targetLocalAddr, serviceName, args, notiChan)
+ _, err := servicemgr.ExecuteApp(targetLocalAddr, serviceName, paramStrWithArgs, notiChan)
checkError(t, err)
select {
func TestExecuteAppWithInvalidArgs(t *testing.T) {
notiChan := make(chan string)
- args := []string{"invalidArgs"}
- _, err := servicemgr.ExecuteApp(targetLocalAddr, serviceName, args, notiChan)
+ _, err := servicemgr.ExecuteApp(targetLocalAddr, serviceName, paramStrWithInvalidArgs, notiChan)
checkError(t, err)
select {
func TestHandleNoti(t *testing.T) {
notiChan := make(chan string, 1)
- id, err := servicemgr.ExecuteApp(targetLocalAddr, serviceName, nil, notiChan)
+ id, err := servicemgr.ExecuteApp(targetLocalAddr, serviceName, paramStr, notiChan)
checkError(t, err)
statusNotificationRequest := make(map[string]interface{})