Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Action: execute mvn spotless:check on push #1766

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ jobs:
working-directory: deploy-service
run: |
mvn clean package --file pom.xml -P-pinterest-dependenies,exclude-pinterest-only-classes
- name: Build with Maven
working-directory: deploy-service
run: |
mvn spotless:check --file pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

import lombok.Data;

@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
Expand All @@ -27,7 +26,8 @@
@AllArgsConstructor
@Data
public class HostBeanWithStatuses extends HostBean {
// Normandie and Knox Statuses are NOT in the hosts table, but instead on the hosts_and_agents table
// Normandie and Knox Statuses are NOT in the hosts table, but instead on the hosts_and_agents
// table
@JsonProperty("normandieStatus")
private NormandieStatus normandie_status;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/**
* Copyright (c) 2024 Pinterest, Inc.
*
* 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.
*/
package com.pinterest.deployservice.bean;

public enum KnoxStatus {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/**
* Copyright (c) 2024 Pinterest, Inc.
*
* 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.
*/
package com.pinterest.deployservice.bean;

public enum NormandieStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.List;
import java.util.Set;
import javax.validation.constraints.NotEmpty;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.pinterest.deployservice.bean.HostBean;
import com.pinterest.deployservice.bean.HostBeanWithStatuses;

import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -72,7 +71,8 @@ void insertOrUpdate(

HostBean getByEnvIdAndHostId(String envId, String hostId) throws Exception;

Collection<HostBeanWithStatuses> getByEnvIdAndHostName(String envId, String hostName) throws Exception;
Collection<HostBeanWithStatuses> getByEnvIdAndHostName(String envId, String hostName)
throws Exception;

Collection<String> getToBeRetiredHostIdsByGroup(String groupName) throws Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ public List<HostBean> getHostsByGroup(String groupName, long pageIndex, int page

@Override
public List<HostBeanWithStatuses> getHosts(String hostName) throws Exception {
ResultSetHandler<List<HostBeanWithStatuses>> h = new BeanListHandler<>(HostBeanWithStatuses.class);
ResultSetHandler<List<HostBeanWithStatuses>> h =
new BeanListHandler<>(HostBeanWithStatuses.class);
return new QueryRunner(dataSource).query(GET_HOST_BY_NAME, h, hostName);
}

Expand Down Expand Up @@ -324,7 +325,8 @@ public HostBean getByEnvIdAndHostId(String envId, String hostId) throws Exceptio
@Override
public Collection<HostBeanWithStatuses> getByEnvIdAndHostName(String envId, String hostName)
throws Exception {
ResultSetHandler<List<HostBeanWithStatuses>> h = new BeanListHandler<>(HostBeanWithStatuses.class);
ResultSetHandler<List<HostBeanWithStatuses>> h =
new BeanListHandler<>(HostBeanWithStatuses.class);
Collection<HostBeanWithStatuses> hostBeans =
new QueryRunner(dataSource)
.query(GET_HOST_BY_ENVID_AND_HOSTNAME1, h, envId, hostName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,13 @@ void updateHosts(
}

void updateHostStatus(
String hostId, String hostName, String hostIp, String agentVersion, String asg,
NormandieStatus normandieStatus, KnoxStatus knoxStatus)
String hostId,
String hostName,
String hostIp,
String agentVersion,
String asg,
NormandieStatus normandieStatus,
KnoxStatus knoxStatus)
throws Exception {
HostAgentBean hostAgentBean = hostAgentDAO.getHostById(hostId);
long currentTime = System.currentTimeMillis();
Expand Down Expand Up @@ -835,10 +840,17 @@ public PingResult ping(PingRequestBean pingRequest, boolean rate_limited) throws
String agentVersion =
pingRequest.getAgentVersion() != null ? pingRequest.getAgentVersion() : "UNKNOWN";

NormandieStatus normandieStatus = pingRequest.getNormandieStatus() != null ? pingRequest.getNormandieStatus() : NormandieStatus.UNKNOWN;
KnoxStatus knoxStatus = pingRequest.getKnoxStatus() != null ? pingRequest.getKnoxStatus() : KnoxStatus.UNKNOWN;

this.updateHostStatus(hostId, hostName, hostIp, agentVersion, asg, normandieStatus, knoxStatus);
NormandieStatus normandieStatus =
pingRequest.getNormandieStatus() != null
? pingRequest.getNormandieStatus()
: NormandieStatus.UNKNOWN;
KnoxStatus knoxStatus =
pingRequest.getKnoxStatus() != null
? pingRequest.getKnoxStatus()
: KnoxStatus.UNKNOWN;

this.updateHostStatus(
hostId, hostName, hostIp, agentVersion, asg, normandieStatus, knoxStatus);

// update the host <-> groups mapping
this.updateHosts(hostName, hostIp, hostId, groups, accountId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
/**
* Copyright (c) 2024 Pinterest, Inc.
*
* 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.
*/
package com.pinterest.deployservice.db;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.pinterest.deployservice.bean.HostAgentBean;
import com.pinterest.deployservice.bean.KnoxStatus;
import com.pinterest.deployservice.bean.NormandieStatus;
import com.pinterest.deployservice.dao.HostAgentDAO;
import java.util.List;
import java.util.UUID;
import org.apache.commons.dbcp.BasicDataSource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class DBAgentDAOImplTest {

private static BasicDataSource dataSource;
Expand All @@ -33,7 +47,6 @@ void tearDown() throws Exception {
DBUtils.truncateAllTables(dataSource);
}


@Test
public void testHostAgentDAO() throws Exception {
final String hostId = "host-1";
Expand All @@ -59,15 +72,18 @@ public void testHostAgentDAO() throws Exception {
assertEquals(1, hostCount);

// Test getStaleHosts
List<HostAgentBean> staleHosts = hostAgentDAO.getStaleHosts(System.currentTimeMillis() - 100_000);
List<HostAgentBean> staleHosts =
hostAgentDAO.getStaleHosts(System.currentTimeMillis() - 100_000);
assertTrue(staleHosts.isEmpty());

List<HostAgentBean> staleHosts2 = hostAgentDAO.getStaleHosts(System.currentTimeMillis() + 100_000);
List<HostAgentBean> staleHosts2 =
hostAgentDAO.getStaleHosts(System.currentTimeMillis() + 100_000);
assertEquals(1, staleHosts2.size());
assertEquals(hostAgentBean, staleHosts2.get(0));

List<HostAgentBean> staleHosts3 = hostAgentDAO.getStaleHosts(
System.currentTimeMillis() - 100_000, System.currentTimeMillis() + 100_000);
List<HostAgentBean> staleHosts3 =
hostAgentDAO.getStaleHosts(
System.currentTimeMillis() - 100_000, System.currentTimeMillis() + 100_000);
assertEquals(1, staleHosts3.size());
assertEquals(hostAgentBean, staleHosts3.get(0));

Expand All @@ -81,16 +97,15 @@ public void testHostAgentDAO() throws Exception {

private HostAgentBean genDefaultHostAgentBean(String hostId) {
return HostAgentBean.builder()
.ip("127.0.0.1")
.host_id(hostId)
.host_name(UUID.randomUUID().toString())
.create_date(System.currentTimeMillis())
.last_update(System.currentTimeMillis())
.agent_version("1.0")
.auto_scaling_group("auto-scaling-group")
.normandie_status(NormandieStatus.OK)
.knox_status(KnoxStatus.OK)
.build();
.ip("127.0.0.1")
.host_id(hostId)
.host_name(UUID.randomUUID().toString())
.create_date(System.currentTimeMillis())
.last_update(System.currentTimeMillis())
.agent_version("1.0")
.auto_scaling_group("auto-scaling-group")
.normandie_status(NormandieStatus.OK)
.knox_status(KnoxStatus.OK)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.joda.time.DateTime;
Expand Down Expand Up @@ -870,13 +869,19 @@ public void testHostDAO() throws Exception {

// Test support for normandie and knox statuses in hostDAO.getHosts
hostDAO.insertOrUpdate(
"host-normandie", "1.1.1.1", "id-normandie", HostState.ACTIVE.toString(), groups, "test");
hostAgentDAO.insert(HostAgentBean.builder()
.host_name("host-normandie")
.host_id("id-normandie")
.normandie_status(NormandieStatus.OK)
.knox_status(KnoxStatus.ERROR)
.build());
"host-normandie",
"1.1.1.1",
"id-normandie",
HostState.ACTIVE.toString(),
groups,
"test");
hostAgentDAO.insert(
HostAgentBean.builder()
.host_name("host-normandie")
.host_id("id-normandie")
.normandie_status(NormandieStatus.OK)
.knox_status(KnoxStatus.ERROR)
.build());

List<HostBeanWithStatuses> hostBeansNormandie = hostDAO.getHosts("host-normandie");
assertEquals(1, hostBeansNormandie.size());
Expand All @@ -888,7 +893,7 @@ public void testHostDAO() throws Exception {
// Test support for normandie and knox statuses in hostDAO.getByEnvIdAndHostName
groupDAO.addHostCapacity("e-3", "host-normandie");
Collection<HostBeanWithStatuses> hostBeansNormandie2 =
hostDAO.getByEnvIdAndHostName("e-3", "host-normandie");
hostDAO.getByEnvIdAndHostName("e-3", "host-normandie");
assertEquals(1, hostBeansNormandie2.size());
HostBeanWithStatuses hostBeanNormandie2 = hostBeansNormandie2.iterator().next();
assertEquals(hostBeanNormandie2.getHost_name(), "host-normandie");
Expand Down
Loading
Loading