-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.cloud.sonic.agent.tools; | ||
|
||
import com.alibaba.fastjson.JSONObject; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Component | ||
@Slf4j | ||
public class PHCTool { | ||
private static String baseUrl = "http://127.0.0.1:7531"; | ||
private static RestTemplate restTemplate; | ||
|
||
@Autowired | ||
public void setRestTemplate(RestTemplate restTemplate) { | ||
PHCTool.restTemplate = restTemplate; | ||
} | ||
|
||
public static void setPosition(int position, String type) { | ||
if (!isSupport()) return; | ||
log.info("set hub position: {} {}", position, type); | ||
JSONObject re = new JSONObject(); | ||
re.put("position", position); | ||
re.put("type", type); | ||
restTemplate.postForEntity(baseUrl + "/control", re, String.class); | ||
} | ||
|
||
public static boolean isSupport() { | ||
try { | ||
ResponseEntity<String> responseEntity = | ||
restTemplate.getForEntity(baseUrl + "/ping", String.class); | ||
if (responseEntity.getStatusCode() == HttpStatus.OK) { | ||
if ("pong".equals(responseEntity.getBody())) { | ||
log.info("hub is ready."); | ||
return true; | ||
} | ||
} | ||
log.info("hub is not ready."); | ||
return false; | ||
}catch (Exception e){ | ||
log.info("hub is not ready. ignore..."); | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file modified
0
src/test/java/org/cloud/sonic/agent/android/MockStepDebugTest.java
100644 → 100755
Empty file.
17 changes: 17 additions & 0 deletions
17
src/test/java/org/cloud/sonic/agent/tools/PHCToolTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.cloud.sonic.agent.tools; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class PHCToolTest { | ||
|
||
@Test | ||
public void test() { | ||
PHCTool.setPosition(2, "up"); | ||
} | ||
|
||
} |